Calculating delay time - bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculating delay time - bash
# 1  
Old 04-14-2009
Calculating delay time - bash

Hi,

I am having the following problem.

test > hourOfDay=06 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime
180
test > hourOfDay=07 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime
120
test > hourOfDay=08 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime
bash: (9-08: value too great for base (error token is "08")
test > hourOfDay=09 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime
bash: (9-09: value too great for base (error token is "09")
test > hourOfDay=10 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime
-60

you can see where hourOfDay = 08 or 09 I get the error
bash: (9-08: value too great for base (error token is "08")

does it think that these are base 8 numbers ?
because of the leading "0" ?

In my script I get the hourOfDay using
hourOfDay=$(date +%H)

Is there an easy way to strip off the '0', if that is the problem ?
(sorry if this is an easy thing, I mess with scripts less than once a month,
so not very experienced).

Thanks !
joe
# 2  
Old 04-14-2009
the leading zero is indeed the problem.

too bad it's not past 1:00pm here.... otherwise i could help. Smilie

but you might try something like:

### Tue Apr 14 11:24:18 EDT 2009
set `date | sed -e 's/:/ /g'`
hours=$4

I think that doesn't have leading zeroes... More after 1:00 if solution isn't posted by then.
# 3  
Old 04-14-2009
Thanks. I will try it ...

FYI - for testing purposes you could use hourOfDay=$(date +%m), to get the month "04".

Thanks !
joe
# 4  
Old 04-14-2009
thanks

date +%m | sed -e 's/0//g'

Seems to do the right thing
# 5  
Old 04-14-2009
Quote:
Originally Posted by jbsimon000
thanks

date +%m | sed -e 's/0//g'

Seems to do the right thing
not quite.
it'll mangle 10:00 o'clock.

Try:

Code:
date +%H | sed -e 's/^0//'

need that caret.
# 6  
Old 04-14-2009
wooo whooo , thanks !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Sendmail delay: 3 mins 11 secs... Every time.

Hi all, I would like some help with a sendmail problem: We have a new system comprising of 4 T7-1 servers, each hosting 5 LDOMs, all domains running Solaris 11.3 All emails sent from every one of these domains (including the control domains) sit in the queue for 3 mins 11 secs (sometime 3m 12s,... (11 Replies)
Discussion started by: Mysturji
11 Replies

2. Shell Programming and Scripting

BASH Execution Delay / Speedup

I have a BASH script that runs a continuous loop, reading a line from a file, and then spawning a background process to use it. I've placed "date" commands inside it to see where it's slowing down, and everything inside -- including reading the line from the file -- is fast, but the loop bogs... (34 Replies)
Discussion started by: gmark99
34 Replies

3. Shell Programming and Scripting

Calculating the running time

Hi All, I want to run a utility for all the process id that are running for more than 15 mins. I have captured process id's and the time that they were run in a file like below 1st column represnts the process ids and the 2nd one is the Time < 21014 01:00 21099 01:00 24361 01:03 24406... (5 Replies)
Discussion started by: r_t_1601
5 Replies

4. Emergency UNIX and Linux Support

Time delay problem in asking password

Hi All, I have solaris-11 global and multiple non-global zones running, which all are on same network. They are not in NIS. When we open putty session and give user-name, it takes long time in asking password (around 40-50 seconds) on Global zone. While on non-global zones, it is working... (9 Replies)
Discussion started by: solaris_1977
9 Replies

5. Shell Programming and Scripting

Calculating the epoch time from standard time using awk and calculating the duration

Hi All, I have the following time stamp data in 2 columns Date TimeStamp(also with milliseconds) 05/23/2012 08:30:11.250 05/23/2012 08:30:15.500 05/23/2012 08:31.15.500 . . etc From this data I need the following output. 0.00( row1-row1 in seconds) 04.25( row2-row1 in... (5 Replies)
Discussion started by: ks_reddy
5 Replies

6. Shell Programming and Scripting

Time delay for awk

I have an awk script, and want to introduce a time delay. How can I do this? (3 Replies)
Discussion started by: kristinu
3 Replies

7. Shell Programming and Scripting

Calculating completion time

The date construct in UNIX can be used to calculate when something is finished: date -v+1H displays the time 1 hour from now. I want to use the same construct in a script, but it is leading to error messages: echo "Finished at: " `date -v+$durationH` where $duration is calculated based on input... (3 Replies)
Discussion started by: figaro
3 Replies

8. Shell Programming and Scripting

bash - delay expansion of variable

Hello - I have a bash script which does some logging, and I'd like to include the line number of the echo statement that pipes into $LOGGER: MYPID=$$ MYNAME=`basename $0` LOGGER="/usr/bin/logger -t $MYNAME($LINENO) -p daemon.error" ... echo 'this is an entry into the log file' | $LOGGER ... (3 Replies)
Discussion started by: scandora
3 Replies

9. Solaris

lock time delay

I have a Sol system. The lock timeout is default 15 minutes. I tried to make it longer but cannot by lock -t timeout Anyon can tell me the cmd in solai for this please. A thank in advance (2 Replies)
Discussion started by: part-time-user
2 Replies

10. BSD

Reduce boot-time delay on FreeBSD?

Say for instance, I would like to reduce the delay/waiting time for the boot-time menu from 10 seconds to 5 seconds, how would I go about doing it? From what I've been able to find, entering "autoboot 5" into the right file would take care of that for me, but the man pages are unclear as to... (1 Reply)
Discussion started by: DownSouthMoe
1 Replies
Login or Register to Ask a Question