PDA

View Full Version : Scripts: Disk usage, SwapIO, Load Avg



mitto
08-30-2006, 03:45 AM
Hello,

I have found this script from below mention URL: Linux Web Admin (http://forums.linuxwebadmin.info/index.php/topic,44.0.html)

I want some more suggestion and modification on this script to make it batter.

Some useful script for yoru server maintenance:

Script which will send you email alert when disk space usage is more than 70%:
----------------------------------------------------------------------------------------------


#!/bin/bash
usage=`df -h | awk '{print $5}' | sed -e N -e 's/\n/ /' | awk '{print $2}' | tr -d % -s "\n"`
devnm=`df -h | awk '{print $1}' | sed -e N -e 's/\n/ /' | awk '{print $2}' | tr -s "\n"`
str="============================="

if [ $usage -ge 70 ]; then
info="Disk usage for $devnm is more than 70% , Current Disk usage is $usage % "
echo -e "$str\n$info\n$str" |mail -s "Alert: Disk Usage for `hostname` on `date`" abc@yourdom.com

else
info="Disk Usage is $usage% for $devnm"
# echo -e "$str\n$info\n$str" | mail -s "Alert: Disk Usage for `hostname` on `date`" abc@yourdom.com
fi

------------------------------------------------------------------------------------------------
Script which will send you email alert when swapIO us more than 100 MB:
---------------------------------------------------------------------------------------------------


#!/bin/bash
io=`free -m | awk '{print $3}' | sed '1,3 d'`
info1="SwapIO is : $io MB"
str="============================="

if [ $io -ge 100 ]; then
info="SwapIO is more than 100 MB"
echo -e "$str\n$info\n$info1\n$str" | mail -s "Alert: SwapIO for `hostname` on `date`" abc@yourdom.com
else
# echo -e "$str\n$info1\n$str" | mail -s "Alert: SwapIO for `hostname` on `date`" abc@yourdom.com
fi

------------------------------------------------------------------------------------------------
Script which will send you email alert wehn load average is more than 5:
-----------------------------------------------------------------------------------------------


#!/bin/bash
avg=`uptime | awk '{print $8" " $9 " "$10 $11 $12 }' | tr -s , " "`
cur=`uptime | awk '{print $10}' | tr -d , | cut -d. -f1`
str="============================="
info="Curent $avg"

if [ $cur -ge 5 ]; then
info1="Server load is high presently"
echo -e "$str\n$info\n$info1\n$str" | mail -s "Alert: Load Average for `hostname` on `date`" abc@yourdom.com
else
# echo -e "$str\n$info\n$str"
fi


-----------------------------------------------------------------------------------------------