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
************************************************
Script abt Filesystem alert
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).
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).
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
Email : azfarhashmi@hotmail.com
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
Email : azfarhashmi@hotmail.com