Search This Blog

Tuesday, February 10, 2009

script to check status of services and mail status

[if necessary use script in crontab, run auto. after a particular interval]
msg="At `date` status of services"

a=`ps -A | pgrep sipXproxy | head -n 1`

if [ ! $a ] ; then
echo "sipx is stopped"
msg=$msg"\n1) sipx is stopped"
else
echo "sipx is running"
msg=$msg"\n1) sipx is running"
fi
sleep 1

b=`ps -A | pgrep siproxd | head -n 1`

if [ ! $b ] ; then
echo "siproxd is stopped"
msg=$msg"\n2) siproxd is stopped"
else
echo "siproxd is running"
msg=$msg"\n2) siproxd is running"
fi
sleep 1

c=`ps -A | pgrep named | head -n 1`

if [ ! $c ] ; then
echo "named is stopped"
msg=$msg"\n3) named is stopped"
else
echo "named is running"
msg=$msg"\n3) named is running"
fi

sleep 1

d=`ps -A | pgrep httpd | head -n 1`

if [ ! $d ] ; then
echo "httpd is stopped"
msg=$msg"\n4) httpd is stopped"
else
echo "httpd is running"
msg=$msg"\n4) httpd is running"
fi
a=""
b=""
c=""
d=""

echo -e "\n$msg"

#echo $msg | sendmail mail_ID_here

#xterm &
#sleep 3
#wall $msg

No comments:

Post a Comment