Error in Partition Monitoring Script!

Taking care of your Linux box.

Error in Partition Monitoring Script!

Postby refra » Fri Nov 05, 2010 10:59 am

AOA,

Here is the File System Monitoring Script: This Script runs through cronjob & monitor a FS usage and raise a mail once if any FS usage is equal or greather than 85%.


############# VARIABLES #######################
EMAIL="sysadmin@company.com"
SUBJECT="Disk Utilization Warning - $(hostname)"
MAILPROG="/bin/mail"
LOG="/tmp/dfmail.tmp"
CHK="/tmp/mailstat.tmp"

################# SCRIPT ######################

clear
echo

echo "removing old mail file"

rm -f $LOG
touch $LOG

echo `date` > $LOG
echo >> $LOG

WARN_VAL=85
df -l | sed 's/ */\,/g' > /tmp/df-out.tmp

cat /tmp/df-out.tmp | while read fs

do

PNAME=`echo $fs | cut -d, -f6`
PUSED=`echo $fs | cut -d, -f5 | cut -d% -f1 `

if test $PUSED -ge $WARN_VAL
then

echo "Partition: $PNAME Utilization: $PUSED%" >> $LOG
echo "Partition: $PNAME Utilization: $PUSED%"

fi

done

WLINE=`wc -l $LOG | cut -d" " -f1`

if test $WLINE -le 0
then
echo "Utilization now under limit removing mail check file"
rm -f $CHK
fi

if test -f $CHK
then

echo "Not sending email"
else

rm -f $CHK
$MAILPROG -s "$SUBJECT" "$EMAIL" < $LOG && touch $CHK
fi
########### OUTPUT & ERROR #######################

./hdalert-old: line 34: test: Use: integer expression expected
./hdalert-old: line 34: test: /dev/mapper/VG1-htdocs: integer expression expected

############### FILE SYSTEM #######################
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 11G 4.0G 6.3G 39% /
udev 250M 104K 250M 1% /dev
/dev/mapper/VG1-htdocs
9.2G 7.3G 1.5G 83% /srv/www/htdocs


Please correct my script.
refra
Naik
 
Posts: 69
Joined: Wed Dec 06, 2006 3:51 pm

Postby lambda » Wed Nov 10, 2010 2:56 pm

paste the output of "df -l", not "df -h".

use the code tag around the output.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore


Return to “%s” Administration

Who is online

Users browsing this forum: No registered users and 3 guests

cron