Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timing a Script Execution In Seconds 2

Status
Not open for further replies.

iaresean

Programmer
Mar 24, 2003
570
ZA
Help,

Ygor had previously answered my question of how to tell linux to run a script later, and how to specifiy how long the system should would wait till it executes the script.

echo "/path/to/script" | at now +5 minutes

This worked great and it seemed like it was exactly what I needed, but unfortunately I was asked to make the delay 5 seconds only instead of 5 minutes. This is a problem because the 'at' command only supports minutes,hours,weeks, and years. NO seconds!!!

Does anybody out there know of another way of doing this or of a similiar command to 'at' that is seconds compatible.

Any and all help and thought put into this is greatly appreciated.

Here is a more full description/history of my problem (for those interested):
I am writing a cgi script(web page) that takes input from the user and uses this input to modify the httpd.conf file. Since apache's configuration file has been modified apache needs to be reloaded so that it uses the new file. Unfortunately this cannot be done while apache is processing a web page. This causes the web page to bomb. So in answer to this I put my restart apache command in a seperate script and using the line at the top made the script only execute 5 minutes later. This means it runs completely seperate to the web page, and apache can then be succesfully reloaded.
Unfortunately it was decided that a minute was too long too wait, and 5 seconds would be more preferable, however the 'at' command doesn't support seconds. So here I am now looking for a command that will tell in linux to execute a script in 5 seconds time, and force the process to run seperate of the web page.

Any ideas?
 
Could you possible put a sleep in for 5 secons and then execute "at now" without a timer?
 
You could try...

(sleep 5; /path/to/script)&
 
Yes, I tried running the script in the background with a five second delay already, but it didn't work. The cgi script waited the five seconds and didn't execute it in the background. Any other ideas?
 
WOW, ok I tried a combination of the few commands that I had recieved from everyone and I have come up with one that works. Here it is for anyone that has a similiar problem:

(sleep 5; echo "/usr/bin/reloadapache" | at now)&

"/usr/bin/reloadapache" being the script that you created that contains the reload apache command.
 
What about...
[tt]
echo 'sleep 5; /path/to/script' | batch
 
Wow Ygor, once again you come through with flying colors, your answer is in fact better than the one I previously used, because the 'at' command keeps on outputing an error message saying that 'a process will occur at....'

Thanks for your time and effort buddy.
 
Sorry guys, one last thing before this discussion is closed:

When I use this command :
echo 'sleep 5; /path/to/script' | batch

It keeps on outputing:
warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/sh
job 43 at 2004-01-06 16:34

How do I stop this from being outputed?
I tried:
echo 'sleep 5; /path/to/script' | batch > /dev/null

But that didn't work.
Any ideas?
 
try

.... 2> /dev/null

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks alot vgersh99!
I am finally finished with this issue!
 
Hi there pfournier.

That is probably the way to go. Thanks a bunch, but could you answer one more question for me? What is the difference between SIGUSR1 and USR1.
Any recommendations/warnings/opinions you can give me on the above.

Thanks, all help is greatly appreciated.
 
SIGUSR1 and USR1 are the same. Some environments recognize one form while others recognize both. Use whichever one works for you.

Only warning would be to make sure the new configuration file is valid before sending SIGUSR1 to Apache.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top