sleeping for 30 seconds

2004-03-26 Thread Richard P. Williamson


Hello world,

I've got a shell script that in essence does this:

FOREVER:
  pre-process stuff
  mainapp
  post-process stuff

If the mainapp returns too soon, the assumption must be that 
there is a configuration problem of some sort.  Under those
conditions, I don't want to immediately jump to the pre-process
stuff and start the mainapp again.

Instead, I want to sleep for an arbitrary time between attempts
(giving an operator some leeway to fix the configuration before
trying again).

If mainapp runs long enough, then it should just post-, pre-
mainapp again immediately.

What's a good sh algorithm for the above?  (assume  10
seconds indicates error condition and a 50 second sleep
between iterations when necessary, and I don't need a
'five attempts then sleep' thing).  Also, assume I've
simplified for the home audience.  The sh script is 
lots more involved then the example above implies. 

rip  

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: sleeping for 30 seconds

2004-03-26 Thread Jan Grant
On Fri, 26 Mar 2004, Richard P. Williamson wrote:

 What's a good sh algorithm for the above?  (assume  10
 seconds indicates error condition and a 50 second sleep
 between iterations when necessary, and I don't need a
 'five attempts then sleep' thing).  Also, assume I've
 simplified for the home audience.  The sh script is
 lots more involved then the example above implies.

You might, if the possibility is there, want to use the exit value of
the main process to indicate errors, which is perhaps a little more
reliable.

If you want the time in seconds between two points, you might try
something like this:

start_time=`date +%s`
# ... do something
end_time=`date +%s`
time_taken=$(($end_time - $start_time))



-- 
jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/
Tel +44(0)117 9287088 Fax +44 (0)117 9287112 http://ioctl.org/jan/
New Freedom of Information Act: theirs, to yours. Happy now?
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: sleeping for 30 seconds

2004-03-26 Thread Richard P. Williamson
At 13:08 26/03/2004, Jan Grant wrote:
On Fri, 26 Mar 2004, Richard P. Williamson wrote:

You might, if the possibility is there, want to use the exit value of
the main process to indicate errors, which is perhaps a little more
reliable.

Except it doesn't tell me how long it ran for before it falling
over, which is the bit I need to look at.

If you want the time in seconds between two points, you might try
something like this:

start_time=`date +%s`
# ... do something
end_time=`date +%s`
time_taken=$(($end_time - $start_time))

That's what I'm looking for, thanks!

(that, and )

if [ $time_taken -lt 10 ]; then
  sleep 50
fi

Regards, and thanks!
rip 

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]