UnixServerAdmin

Server Administration & Management

load_scan.sh

###########################################################
## load_scan.sh ##
###########################################################
#!/bin/bash
#This script will send mail alert if load is high in server with w,pstree,mysqladmin,exim queue results

echo “############ SERVER LOAD REPORT ############” > /load.txt

#Enter the Load Average
l=”30″

v=`cat /proc/loadavg |awk ‘{print $1 }’ |cut -d”.” -f1 `

if [ $v -ge $l ]
then

cd /
touch load.txt

#Enter the Text that you needs to dispaly on mail

echo “Please check the Server and reduce the Load” >> /load.txt
echo ”       ” >> /load.txt
echo ”       ” >> /load.txt

echo  “LOAD STATUS RUN ON” `date` >> /load.txt
echo “====================================================================” >> /load.txt
echo “====================================================================” >> /load.txt

echo ” W Results  ” >> /load.txt

echo ”       ” >> /load.txt
echo ”       ” >> /load.txt
w >> /load.txt
echo “====================================================================” >> /load.txt
echo “====================================================================” >> /load.txt

echo “TOP Results” >> /load.txt
echo “====================================================================” >> /load.txt

#pstree -apu >> load.txt
ps -eo pcpu,pid,user,args | sort -k 1 -r | head -20 >> /load.txt
echo “====================================================================” >> /load.txt
echo “====================================================================” >> /load.txt
echo ”       ” >> /load.txt
echo ”       ” >> /load.txt
echo “MYSQLADMIN Results” >> /load.txt
echo “====================================================================” >> /load.txt

echo ”       ” >> /load.txt
echo ”       ” >> /load.txt
mysqladmin proc >> /load.txt

echo “====================================================================” >> /load.txt
echo “====================================================================” >> /load.txt

echo “NETSTAT RESULTS (FOR CHKING DDOS ATTACK..10 HIGH HTTP CONNECTIONS ) ” >>/load.txt

echo >>/load.txt
netstat -plan |grep :80 | awk ‘{print $5}’ |cut -d: -f1 |sort |uniq -c |sort -n |tail -10 >>/load.txt

echo “====================================================================” >> /load.txt
echo “====================================================================” >> /load.txt

echo ”       ” >> /load.txt
echo ”       ” >> /load.txt
echo ”       ” >> /load.txt
echo “Thanks & Regards” >> /load.txt
echo “Unixserveradmin.com Security Team” >> /load.txt

mail -s “!!!Urgent HIGH LOAD Avg=$v in  $HOSTNAME ” unixserv@unixserveradmin.com info@unixserveradmin.com  < /load.txt

>/load.txt

fi
###########################################################

Advertisements

May 5, 2011 - Posted by | Shell Script |

3 Comments »

  1. This is a great post. Thank you for taking the time to describe all of this out for folks. It really is a great help!

    Comment by Mariko Fulbright | June 15, 2011 | Reply

  2. I would like to read all that you know about this topic. You just have scraped the surface of your knowledge on this which is obvious from the way you compose. Have you thought about dedicating a whole web page in order that people won’t miss what you must say?

    Comment by fresh water | June 16, 2011 | Reply

  3. Hi,

    Thanks dev… :)

    Comment by punit | June 13, 2012 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: