Wednesday, 5 September 2012

Shell script to Monitor Server services


#!/bin/sh
pro=`ps ax | grep /usr/sbin/httpd | grep -v grep | cut -c1-5 | paste -s -`
if [ "$pro" ];
then
echo "Apache is running"
Apache=1
else
echo "Apache is not running"
Apache=0
fi

pro1=`ps ax | grep /usr/sbin/dk-filter | grep -v grep | cut -c1-5 | paste -s -`
if [ "$pro1" ];
then
echo "dkim is running"
dkim=1
else
echo "dkim is not running"
dkim=0
fi

pro2=`ps ax | grep sendmail | grep -v grep | cut -c1-5 | paste -s -`
if [ "$pro2" ];
then
echo "Sendmail is running"
Sendmail=1
else
echo "Sendmail is not running"
Sendmail=0
fi

pro3=`ps ax | grep /usr/sbin/named | grep -v grep | cut -c1-5 | paste -s -`
if [ "$pro3" ];
then
echo "named is running"
named=1
else
echo "named is not running"
named=0
fi

pro4=`ps ax | grep /usr/libexec/postfix/master | grep -v grep | cut -c1-5 | paste -s -`
if [ "$pro4" ];
then
echo "postfix is running"
postfix=1
else
echo "postfix is not running"
postfix=0
fi

pro5=`ps ax | grep /usr/libexec/mysqld | grep -v grep | cut -c1-5 | paste -s -`
if [ "$pro5" ];
then
echo "mysqld is running"
my=1
else
echo "mysqld is not running"
my=0
fi

pro6=`service iptables status | egrep '^Table:'`
if [ "$pro6" ];
then
echo "Firewall is running"
iptables=1
else
echo "Firewall is not running"
iptables=0
fi

pro7=`ps ax | grep /usr/sbin/sshd | grep -v grep | cut -c1-5 | paste -s -`
if [ "$pro7" ];
then
echo "sshd is running"
ssh=1
else
echo "sshd is not running"
ssh=0
fi

pro8=`ps ax | grep /usr/sbin/pmtad | grep -v grep | cut -c1-5 | paste -s -`
if [ "$pro8" ];
then
echo "PMTA is running"
PMTA=1
else
echo "PMTA is not running"
PMTA=0
fi


pro9=`ps ax | grep crond | grep -v grep | cut -c1-5 | paste -s -`
if [ "$pro9" ];
then
echo "crond is running"
crond=1
else
echo "crond is not running"
crond=0
fi

MEM= free | grep Mem | awk '{ printf("Free Memory: %.4f %\n", $4/$2 * 100.0) }'

No comments:

Post a Comment

Twitter Bird Gadget