#!/bin/sh
# @author Yuri Timofeev <tim4dev@gmail.com>
# @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public License

# *** start setup ***
ADMIN="admin@email.com"

# calculated experimentally
ALERT=98
# *** end setup ***

ERR=0

# if necessary, change the following line (what FS is not want to track)
for STR in `df -h | grep -vE '^Filesystem|tmpfs|cdrom|dm-|hda1|hda6|hda5' | awk '{ print $5 "___" $1 }'`
do
  usep=$(echo $STR | awk -F "___" '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $STR | awk -F "___"  '{ print $2 }' )
  if [ "$usep" -ge "$ALERT" ]; then
     # for debug !      echo "Out of space \"$partition ($usep%)\" on $(hostname) as on $(date)"
     echo "Out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" | \
          mail -s "ALERT: out of disk space $usep" $ADMIN
     ERR=1
  fi
done

if [ "${ERR}" == "0" ]; then
   exit 0;
else
   exit 1;
fi


