Using a script to check on the program is a good idea but using grep will always lead to problems. grep is unable to tell the difference between user xyz and program xyz or a process that has xyz in the command line. Just put something like this in cron:
#!/usr/bin/sh
# monitor a specific program
# report if not running or more than 1 is running
# Usage: watchprog program_name
set -u
PATH=/usr/bin
MYNAME=${0##*/}
if [ $# -lt 1 ]
then
echo "\nUsage: $MYNAME program_name\n"
exit 1
fi
MYPROG="$1"
PROCLIST=$(UNIX95= ps -C $MYPROG -o pid | grep -v "PID")
if [ "$PROCLIST" = "" ]
then
echo "$MYPROG stopped $(date)" | mailx -s"$MYPROG stopped" root
exit 2
fi
PROCNUM=$(echo "$PROCLIST" | wc -l)
if [ $PROCNUM -gt 1 ]
then
echo "$MYPROG multiple copies running, PIDs= $PROCLIST $(date)" \
| mailx -s"$MYPROG more than 1 copy" root
exit 3
fi
exit
Put this in cron, perhaps running every 10 minutes:
0,10,20,30,40,50 * * * * /usr/contrib/bin/monprog mydaemon
Bill Hassell, sysadmin