#!/bin/bash
#       This script determines the percentage of disk usage.
#       If that percentage is greater than 90% a user is emailed
#       a report notifying them of the usage.
#
#       Copyright 2006 Daniel McCarthy
# BE SURE TO CHANGE THIS TO YOUR EMAIL ADDRESS ;)
emailUser="user@domain.com"
typeset -i error="90"
if [ -e temp.txt ]; then
  rm temp.txt
fi
for disc in `mount| egrep '^/dev' | egrep -iv 'cdrom|proc|sys|pts' |awk '{print $3}'`
do
  typeset -i discUsage=`df -h $disc|cut -c40-42|grep -i [^a-z]`
  if [ "$discUsage" -ge "$error" ]; then
    echo "Disk usage for $disc is at $discUsage%" >> /root/temp.txt
  fi
done
if [ -e temp.txt ]; then
  message=`cat temp.txt`
fi
if [ ${#message} -gt 0 ]; then
  cat /root/temp.txt | mail  -s "Disk Usage Report for: $HOSTNAME" $emailUser
fi


