Verifier qu'un demon tourne

Voici un cht’i script bash a executer en cron. Trois exemple pour squid, qmail et le pop3(qmail)





#!/bin/sh
ps -ef | grep squid | grep -v grep
[ $? -ne 0 ] && {
/etc/init.d/squid restart
sleep 30
}

ps -ef | grep qmail | grep -v grep
[ $? -ne 0 ] && {
/etc/init.d/qmail restart
sleep 30
}
ps -ef | grep pop3d | grep -v grep
[ $? -ne 0 ] && {
/etc/init.d/qmail restart
sleep 30
}

Methode #2


#!/bin/sh -e

pid=/var/run/mon/mon.pid
running_mon_pid=`cat $pid 2>/dev/null` || true

[ -f $pid -a /proc/"$running_mon_pid"/exe -ef /usr/bin/perl ] || /etc/init.d/mon restart

exit 0