Stopping a shell script from running after 24 hours
Hi there --
I am writing a shell script that is doing a check of our filesystems. I would like to program a command within the script to stop after twenty-four hours of running. What would the correct syntax be to accomplish this? Thanks. |
You are not providing any useful information but here are some pointers:
Determine the PID of the script you are running http://www.cyberciti.biz/faq/howto-d...er-linux-unix/ man date man at man kill But perhaps it would be better if you wrote the script so it knew when it had finished, with or without errors, and exited cleanly, with an appropriate exit code. |
There are also a couple of applications I've come across, named timeout and timelimit, that can restrict a running process to a set time, and then terminate it. There may be others as well.
|
Hi there --
Sorry about the vagueness in my posting. What I am trying to do is determine what the process ID for the command running within the script is, and kill it. What I need is the command syntax to do that. As far as the twenty-four hour time period is concerned, I would use the following command syntax prior to killing the process: Code:
sleep 24h |
I don't think you want to use sleep like that. That would simply mean that your script does nothing for 24 hours. Sleep suspends the process for the set period of time, then allows it to run again.
I've already mentioned two applications that should do exactly what you want. Install one or both of them through your package manager, read their man pages, and give them a try. |
Hi there --
I went ahead with your suggestion, and I installed TimeOut onto the system. I included it within the script, and did a test run with the interval set to 300 seconds, or five minutes. The application in question ran in the specified time, and was then shut down. Thanks again for the help. |
Ever looking for the simplest solution, how about starting the script to be killed with this
Code:
(sleep 24h; kill -9 $$)& |
All times are GMT -5. The time now is 03:28 AM. |