Tuesday, October 27, 2009

Check disk space

#!/bin/sh
#
# Put below line your email
#
#ADMIN= email@address
#
STATUS=90 # Set here Alert level
STATUS_F=99 # Set here Warning Level
#
#-----------------------------------------
#
# Please uncomment below line for debug
#set -x
#-----------------------------------------
#
# Do not change anything from below lines
#
#=========================================
#
/bin/df -HP | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )

if [ $usep -ge $STATUS_F ]; then
#
echo "Running disk space is FULL \"$partition ($usep%)\" on $(hostname) as on $(date +%d-%m-%Y)" |
mail -s "!!!WARNING: Disk space is FULL !!! $usep%" $ADMIN
#
else
if [ $usep -ge $STATUS ]; then
#
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date +%d-%m-%Y)" |
mail -s "Alert: Almost out of disk space $usep%" $ADMIN
#
fi
fi
done

No comments :

Post a Comment