#/usr/local/bin/perl # # This script should be run from cron to watch a particular process # and restart it if it dies. # # usage: watcher prog_to_watch prog_to_restart # # Barb Dyker # barb@cs.colorado.edu # 9/14/92 require 'syslog.pl'; if ( $#ARGV < 1 ) { print "Usage: watcher prog_to_watch prog_to_restart"; exit 1; } &openlog($0,'cons,pid','local0'); $watching = $ARGV[0]; shift; @restart = @ARGV; @ps = `ps -ax`; $hits = grep(/$watching/,@ps); if ( $hits == 0 ) { &syslog('info','Restarting %s', $restart[0]); exec(@restart); } elsif ( $hits > 1 ) { &syslog('warning','Too many instances of %s', $restart[0]); } &closelog();