LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 10-06-2009, 02:20 PM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Rep: Reputation: 39
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.
 
Old 10-06-2009, 03:02 PM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
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.
 
Old 10-06-2009, 03:50 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.
 
Old 10-06-2009, 03:51 PM   #4
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Original Poster
Rep: Reputation: 39
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.
 
Old 10-06-2009, 04:29 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.
 
Old 10-06-2009, 06:58 PM   #6
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Original Poster
Rep: Reputation: 39
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.
 
Old 10-07-2009, 02:45 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Ever looking for the simplest solution, how about starting the script to be killed with this
Code:
(sleep 24h; kill -9 $$)&
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
running a shell script which invokes another shell program!!! raghu123 Programming 1 08-04-2008 09:10 AM
In which shell is the script running? indiancosmonaut Solaris / OpenSolaris 5 10-23-2007 12:13 AM
Server aburptly stops running High CPU usage PERL script after about 5 hours bpmee Linux - Server 3 05-18-2007 11:24 AM
stopping command issued from shell script mr_scary Programming 10 01-12-2007 03:29 PM
c/c++ running a shell script? thermalpants Programming 3 05-12-2002 11:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration