Wednesday, April 13, 2011

space alert on filesystem

#!/bin/ksh
LOG=/export/home/space.log
cat /dev/null > $LOG
df -g | sort -rnk 4 | grep -vE '^-|Free|proc' | awk '{sub (/%/,"",$4);print $4 "\t" $7}' | while rea
d output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
#echo $usep
#echo $partition
if [ $usep -ge 70 ]; then
echo "Alert :$usep% used on $partition on $(hostname) \n" >> $LOG
fi
done
####################
if [[ -s $LOG ]]; then
#echo "sending mail"
mailx -s "space alert on $(hostname)" jignesh.kankrecha@xxx.com < $LOG
else
#echo "not sending"
fi;