#!/bin/sh
# This script will check for load above 80% and notify the support admin team as per the email define in TO varaible.
DATE=`date +%y%m%d-%H%M%S`
# Check the Load on the host
if [ `uptime | awk '{ print$10 }' | cut -d. -f1` -gt 80 ];
then
echo "============================================" >> /tmp/CPUload_$DATE
# Get a list of top 10 processes currently utilising the most CPU.
echo "List of Top Process:" /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
`ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/CPUload_$DATE `
# Alert Support personnel about CPU as well the top 10 processes using most CPU
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo "List of Top 10 Mmemory Consuming Processes" >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
`ps axo %mem,pid,euser,cmd | sort -nr | head -n 10 >> /tmp/CPUload_$DATE `
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo "Load averages during this time" >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
uptime >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
free -m >> /tmp/CPUload_$DATE
else
mem=`free -b | awk '{ print$4}'`
echo $mem | cut -c7-
mem1=`echo $mem | cut -c7- `
x1=`echo $mem1 | cut -d " " -f1`
x2=`echo $mem1 | cut -d " " -f2`
x3=`echo $mem1 | cut -d " " -f3`
free=`expr $x1 + $x2`
if [ $free -lt 512000000 ];
then
# Get a list of top 10 processes currently utilising the most CPU.
echo "List of Top Process:" >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
`ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/MemLoad_$DATE `
# Alert Support personnel about CPU as well the top 10 processes using most CPU
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo "List of Top 10 Mmemory Consuming Processes" >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
`ps axo %mem,pid,euser,cmd | sort -nr | head -n 10 >> /tmp/MemLoad_$DATE `
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo "Load averages during this time" >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
uptime >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
free -m >> /tmp/MemLoad_$DATE
else
continue
fi
fi
find '/tmp' -name '/tmp/CPUload*' -mtime +3 -exec rm {} \;
find '/tmp' -name '/tmp/MemLoad*' -mtime +3 -exec rm {} \;
exit
# This script will check for load above 80% and notify the support admin team as per the email define in TO varaible.
DATE=`date +%y%m%d-%H%M%S`
# Check the Load on the host
if [ `uptime | awk '{ print$10 }' | cut -d. -f1` -gt 80 ];
then
echo "============================================" >> /tmp/CPUload_$DATE
# Get a list of top 10 processes currently utilising the most CPU.
echo "List of Top Process:" /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
`ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/CPUload_$DATE `
# Alert Support personnel about CPU as well the top 10 processes using most CPU
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo "List of Top 10 Mmemory Consuming Processes" >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
`ps axo %mem,pid,euser,cmd | sort -nr | head -n 10 >> /tmp/CPUload_$DATE `
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo "Load averages during this time" >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
uptime >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
echo " " >> /tmp/CPUload_$DATE
free -m >> /tmp/CPUload_$DATE
else
mem=`free -b | awk '{ print$4}'`
echo $mem | cut -c7-
mem1=`echo $mem | cut -c7- `
x1=`echo $mem1 | cut -d " " -f1`
x2=`echo $mem1 | cut -d " " -f2`
x3=`echo $mem1 | cut -d " " -f3`
free=`expr $x1 + $x2`
if [ $free -lt 512000000 ];
then
# Get a list of top 10 processes currently utilising the most CPU.
echo "List of Top Process:" >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
`ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> /tmp/MemLoad_$DATE `
# Alert Support personnel about CPU as well the top 10 processes using most CPU
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo "List of Top 10 Mmemory Consuming Processes" >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
`ps axo %mem,pid,euser,cmd | sort -nr | head -n 10 >> /tmp/MemLoad_$DATE `
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo "Load averages during this time" >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
uptime >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
echo " " >> /tmp/MemLoad_$DATE
free -m >> /tmp/MemLoad_$DATE
else
continue
fi
fi
find '/tmp' -name '/tmp/CPUload*' -mtime +3 -exec rm {} \;
find '/tmp' -name '/tmp/MemLoad*' -mtime +3 -exec rm {} \;
exit
No comments:
Post a Comment