Results 1 to 3 of 3
Hi there, I have a c-shell script which executes some programs. In some times one of the programs stops and then the script crashes. As the script is started by ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-11-2010 #1
- Join Date
- Nov 2010
When the script stops
I have a c-shell script which executes some programs. In some times one of the programs stops and then the script crashes.
As the script is started by crontab, I can't kill the script and start it again. So I'm trying to figure out some way to check when the script is crashed.
One idea is to check how long time the script is running. It can't run for more than 2 minutes. If the script runs for more than 2 minutes, one of the programs stoped and the script is crash.
How can I do that? Comments are welcome.
- 11-20-2010 #2
- Join Date
- Apr 2004
I think the most reliable method is to spit out the script's PID into a file in /var/run. Use $$ to get the script's PID from inside the script. Delete the file when you are done.
While that's going on, kick off another process which waits two minutes then checks for the file and kills the process using the PID in the file.
(The $$ thing is based on bash since I don't have csh handy, but if it doesn't work verbatim some light googling should turn up the right csh variable)
Let us know how you get on,
ChrisTo be good, you must first be bad. "Newbie" is a rank, not a slight.
- 11-20-2010 #3
kakariko81280 gives good advise with the pidfile.
What you can do additionally is to write a wrapper script, that
- checks for the pidfile
- if no, starts your script
- if yes, checks for the process
- if there is a process, does nothing
- if no process, deletes pidfile and starts process
That wrapper script can be run by cron every 2minYou must always face the curtain with a bow.