Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    When the script stops

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


  2. #2
    Linux Enthusiast
    Join Date
    Apr 2004
    Hi there,

    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,

    To be good, you must first be bad. "Newbie" is a rank, not a slight.

  3. #3
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    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 2min
    You must always face the curtain with a bow.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts