Shell Script Disk Usage Notification

!/bin/sh

Alert Email Address

ALERT_EMAIL=”email address”
ALERT_LEVEL=10
NO_MONITOR=”/dev/shm” #use pipe to separate multiple

function calculate_usage()
{
while read raw_input;
do
used_space=$(echo $raw_input | awk ‘{ print $1}’ | cut -d’%’ -f1)
partition=$(echo $raw_input | awk ‘{print $2}’)
if [ $used_space -ge $ALERT_LEVEL ] ; then
echo “Running out of Space \”$partition ($used_space%)\” on server $(hostname), $(date)” | \
mail -s “Alert: Almost out of Disk Space $used_space%” $ALERT_EMAIL
fi
done
}

if [ “$NO_MONITOR” != “” ] ; then
df -HP | grep -vE “^Filesystem|tmpfs|cdrom|${NO_MONITOR}” | awk ‘{print $5 ” ” $6}’ | calculate_usage
else
df -HP | grep -vE “^Filesystem|tmpfs|cdrom” | awk ‘{print $5 ” ” $6}’ | calculate_usage
fi

copy script to /etc/cron.daily and make it executable.