This needs to be run as root
Put it in a cron job to fire every minute
#!/bin/sh
DOWN=0
read DOWN <status.txt
if [ $DOWN -eq 1 ]
then
if [ `ps -ef|grep tomcat|grep -v grep|wc -l` -gt 0 ]
then
NOW=`date`
subject="tomcat recovered $NOW"
address="[email protected]"
ps -ef|grep tomcat5 >att.txt
mail -s "$subject" "$addr" -- -fno-reply@yourdomain< att.txt fi
DOWN=0
fi
if [ `ps -ef|grep tomcat|grep -v grep|wc -l` -lt 1 ]
then
NOW=`date`
subject="tomcat down $NOW"
address="[email protected]"
ps -ef|grep tomcat5 >att.txt
mail -s "$subject" "$addr" -- -fno-reply@yourdomain< att.txt fi
DOWN=1
service tomcat5 restart
fi
echo $DOWN >status.txt
On 22/03/11 5:54 PM, "Jorge Infante Osorio" <[email protected]> wrote:
#!/bin/sh
if [ `ps -ef|grep tomcat|grep -v grep|wc -l` -lt 1 ]
then
NOW=`date`
subject="tomcat down $NOW"
address="[email protected]"
ps -ef>att.txt
mail -s "$subject" "$addr" -- -fno-reply@yourdomain< att.txt fi