LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Stopping a shell script from running after 24 hours (https://www.linuxquestions.org/questions/linux-software-2/stopping-a-shell-script-from-running-after-24-hours-760125/)

kaplan71 10-06-2009 02:20 PM

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.

tredegar 10-06-2009 03:02 PM

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.

David the H. 10-06-2009 03:50 PM

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.

kaplan71 10-06-2009 03:51 PM

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
Thanks.

David the H. 10-06-2009 04:29 PM

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.

kaplan71 10-06-2009 06:58 PM

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.

catkin 10-07-2009 02:45 AM

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.