Friday, December 09, 2011

check the disk space availablity

Script to check the disk space and mail if the disk space availablity is below the warning or critical thresholds

### Variable declaration ####
WARN=75
CRITICAL=77
ADMINI_LABS="useremailaccount"


#### Collecting Disk space information #####
df -h |grep -vE 'tmpfs|Filesystem|cdrom'|awk '{print $5 " " $6}' > /tmp/disksize

while read output; do
diskusage=$(echo $output|awk '{print $1}' |cut -d% -f1 )
filesystem=$(echo $output |awk '{print $2}' )
if [ $diskusage -ge $WARN ] && [ $diskusage -le $CRITICAL ]; then
mail -s"WARNING: $(hostname) : Running out of space $filesystem $diskusage" $ADMIN_ILABS
elif [ $diskusage -ge $CRITICAL ]; then
mail -s "CRITICAL: $(hostname) : Running out of space $filesystem $diskusage" $ADMIN_ILABS
fi
done < /tmp/disksize

## File Clean up ##
rm -f /tmp/disksize

No comments: