restart services
Below is a restart script for sendmail which will restart the
downed service and send email. You can modify this script to
check and monitor any service.
You can use this crontab to have this script run every 10 minutes
1,10,20,30,40,50 * * * * /usr/scripts/sendmail-check.sh > /dev/null 2>&1
#!/bin/sh
#
# see if the service if running
COUNT=`ps waux |grep -v grep|grep -c sendmail`
#
# if the service if running quit
if [ $COUNT != 0 ]
then
echo $COUNT " is o.k. exiting..."
#
# if the service is not running...
else
echo "sendmail is down on server... Restarting...."
#
# politely stop and start the service
/etc/rc.d/init.d/sendmail stop
wait 10
/etc/rc.d/init.d/sendmail start
#
# e-page/e-mail someone so they will know there was a problem
cat /usr/scripts/problem.msg |mail -s "sendmail down on ns" bob@domain.com
#
fi
Back to SALUG Main Page