Simple watchdog script for monitoring linux processes (e.g. cgminer)
#!/bin/bash
NAME=cgminer
START=”sudo -u pi screen -dmS cgminer /home/pi/cgminer/cgminer”
GREP=/bin/grep
PS=/bin/ps
NOP=/bin/true
DATE=/bin/dateNOTIFY=person1email
NOTIFYCC=person2email
MAIL=/bin/mail
RM=/bin/rm$PS -ef|$GREP -v grep|$GREP $NAME >/dev/null 2>&1
case „$?” in
0)
# It is running in this case so we do nothing.
$NOP
;;
1)
echo „$NAME is NOT RUNNING. Starting $NAME and sending notices $(date).” >> /home/pi/cgminer/status.log
$START
NOTICE=/tmp/watchdog.txt
echo „$NAME was not running and was started on `$DATE`” > $NOTICE
$MAIL -n -s „watchdog notice” -c $NOTIFYCC $NOTIFY < $NOTICE
$RM -f $NOTICE
;;
esacexit