Revision 2 not available (showing current revision instead)

Watchdog script

Difference between revision 4 and current revision

Summary: Recently I received some beta software that I had to integration-test with our own software. However this software kept crapping out and made this . . .

No diff available.

Recently I received some beta software that I had to integration-test with our own software. However this software kept crapping out and made this impossible.

The following shell script is a quick and dirty way to try and keep up a process.

  #!/bin/sh
  
  # This script will periodically check whether a process still runs and if
  # not, will run a predefined action (such as starting it again).
  
  # Name of process that must be watched
  procname="myproc.sh"
  
  # Command to execute if watched process failed. If this is not a process
  # that runs in the background, add an ampersand to the command. Separate
  # multiple commands with a semicolon. Don't add double quotes, since
  # this might pass multiple parameters as one parameter.
  action=./$procname &
  
  # When the watched process was found not running, the date is written
  # to this file along with any output that the process prints on stdout
  # when it's started again.
  logfile="$0.log"
  
  ###########################################################################
  # No user-configurable code below
  
  while [ 1 ]; do
      nrproc=`ps -e | awk '{print $4}' | grep myproc.sh  | wc -l`
      if [ $nrproc == '0' ]; then
          output=`$action`
          date >> $logfile
          echo "$output" >> $logfile
          sleep 10
      else
          sleep 1
      fi
  done

Watch out with this script, though. If you kill it, then the started process will also die. There might be many more bugs and issues.