Script abt Filesystem alert

Taking care of your Linux box.

Script abt Filesystem alert

Postby telenor » Fri Mar 12, 2010 3:35 pm

AOA,

I made a following script that check filesystem, if any filesystem exceed to 90% then riase an alert only 1 time, but following script generate an alert every 5 minutes according to cronjob. so i need a correction on the script.

************************************************
ALERT="90"
ALERT1="85"
DFH="/tmp/dfout"
DFM="/tmp/dfmail"
CHK="/tmp/hdsize-chk"

rm -f $DFM

clear
echo

echo `date` | tee $DFM
echo | tee -a $DFM

df -h > $DFH
cat $DFH | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;

do
#echo $output
USEP=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
FS=$(echo $output | awk '{ print $2 }' )
if [ $USEP -gt $ALERT ]
then
echo "Running out of space \"$FS - ($USEP%)\"" | tee -a $DFM
fi
done

if test -f $CHK
then
echo "Not Sending an Email"
exit

else

echo Sending an Email
$MAILPROG -s "$SUBJECT" "$EMAIL" < $DFM

echo Creating Tmp File
touch $CHK

fi

if [ $USEP -lt $ALERT1 ]
then
echo Removing Tmp File
rm -f $CHK

fi

************************************************
telenor
Havaldaar
 
Posts: 104
Joined: Tue Mar 29, 2005 11:08 am

Postby azfar » Tue Mar 23, 2010 12:16 am

just forget it and tell us what is your requirement.
Azfar Hashmi
Email : azfarhashmi@hotmail.com
azfar
Captain
 
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
WLM: azfarhashmi@hotmail.com
Yahoo Messenger: azfarhusain@yahoo.com
Location: Karachi

Postby telenor » Wed Mar 24, 2010 1:31 pm

AOA Azfar,


Here is my File System:

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 8.3G 11G 45% /
/dev/sda3 40G 33G 5.2G 87% /d01
none 3.9G 0 3.9G 0% /dev/shm
/dev/sdb 148G 113G 28G 81% /san
/dev/sdc 50G 9.0G 38G 20% /san01
/dev/sdd 403G 303G 79G 80% /san00

If any of the above filesystem exceed to 90% then riase an email alert only 1 time coz script will run with cronjob (after every 5 min).
telenor
Havaldaar
 
Posts: 104
Joined: Tue Mar 29, 2005 11:08 am

Postby azfar » Thu Mar 25, 2010 2:49 pm

here you go

Code: Select all

email="root"
mbody=/tmp/body
subject="Disk Usage Warning"
usage=`df -h /dev/sda1 /dev/sda3 /dev/sdb /dev/sdc /dev/sdd | awk 'NR==1{next}{ if ($5 > 90) print $6 " is at " $5;}'`
if [ -n "$usage" ]; then
echo "$usage" > $mbody
mail -s "$subject" "$email" < $mbody
fi

Azfar Hashmi

Email : azfarhashmi@hotmail.com
azfar
Captain
 
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
WLM: azfarhashmi@hotmail.com
Yahoo Messenger: azfarhusain@yahoo.com
Location: Karachi

Postby telenor » Fri Mar 26, 2010 12:36 pm

Dear Azfar,

Thanks for the Help.


If i run this script with crontab and file system is also exceed then this script raise an email alert every 5 minute.


Plz add something that raise an alert only 1 time not an every 5 minute.
telenor
Havaldaar
 
Posts: 104
Joined: Tue Mar 29, 2005 11:08 am

Postby azfar » Fri Mar 26, 2010 1:23 pm

dude the script just send an email alert (if the condition matched) whenever you run it, so you need to create an cron entry for any interval you want.
Azfar Hashmi

Email : azfarhashmi@hotmail.com
azfar
Captain
 
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
WLM: azfarhashmi@hotmail.com
Yahoo Messenger: azfarhusain@yahoo.com
Location: Karachi


Return to “%s” Administration

Who is online

Users browsing this forum: No registered users and 1 guest