Stopping a shell script from running after 24 hours
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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:
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.