Search

Tuesday, August 19, 2008

shell script to check Server Status

#!/bin/bash
clear
#Global variable
#Please enter the free memory you want to keep in server else mail will send
FMEM=10
#Please Enter free disk Space in MB
FDSK=1000
#Your Default Gateway
DGATE=20.12.31.101
#Please enter the email address
EMAIL=mailtodaman@gmail.com
#Enter the name of the http server you want to monitor.
SNAME=http://linuxguruji.blogspot.com
#Your SMTP Service
SMTP=mailtodaman@gmail.com
#Default Time for SMTP
SEL=5

TMEM=`free -m | awk '{ print $2}' | head -n 2 | tail -1`
echo "Total Memory(Mb) in your system is -->" $TMEM

MEM=`free -m | awk '{ print $4}' | head -n 2 | tail -1`
echo "Free Memory(Mb) in your system is -->" $MEM

FDSK=`df -h | awk '{ print $4}' | head -n 2 | tail -1`
echo "Free HardDisk(Kb) in your System is -->" $FDSK
FDSKK=`df | awk '{ print $4}' | head -n 2 | tail -1`
last | awk '{ print $3}' > a.bat
w | grep pts | awk '{ print $3}' > current.bat


if [ "$MEM" > "$FMEM" ]; then
mail -s " Critical --> Your server memory " $EMAIL <<> "$FDSKK" ]; then
mail -s " Critical --> Your server HDD " $EMAIL <<> Your server Has Hacked " $EMAIL <<>> last.bat

fi
done

for uname1 in $(cat current.bat);
do if [ "$DGATE" != "$uname1" ]; then
mail -s " Critical --> Your server Has Hacked " $EMAIL <<>> last1.bat


fi
done
if ! $(lynx -head -dump "$SNAME" 2> /dev/null | head -1 \
| grep ' 200 ' > /dev/null )
then
mail -s " Critical --> Your site is down " $EMAIL <<> mtest.bat



for uname2 in $(cat mtest.bat);
do if [ "$SMTP" = "$uname2" ]; then
mail -s " Critical --> Your SMTP Service " $EMAIL << EOF
Hello,
Your SMTP Service is not working fine.
Regards,
System Admin
EOF


fi
done

No comments: