#!/bin/sh
    # Shell script to monitor or watch the disk space
    # It will send an email to $ADMIN, if the (free avilable) percentage
    # of space is >= 90%
    # -------------------------------------------------------------------------
    # Linux shell script to watch disk space (should work on other UNIX oses )
    # set admin email so that you can get email
    #ADMIN="sainath@glovision.co"
    # set alert level 50% is default
    ALERT=90
#    df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
df -h | ( read header ; echo "$header" ; sort -rn -k 5)| grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }'| while read output;
    #df -H | grep -vE '^Filesystem|tmpfs|cdrom' | tail -n+2 | awk '{ printf "%d", $5 "" $1}' | while read output;
    do
  #  echo $output
    usep=$(echo $output | awk '{ printf "%d", $1}' | cut -d'%' -f1 )
    partition=$(echo $output | awk '{ printf "%d", $0 }' )
    diskoutput=$(df -H | awk '{ print $0 " " $1}' | sort -rk5 -g| sed 's/%//g')
    if [ $usep -ge $ALERT ]; then
echo -e "Running out of space \"$partition ($usep%)\\n\n$output\\n\n$diskoutput" 2>&1 | sed '1!b;s/^/To: anudeep@glovision.co,support@glovision.co,supportit@glovision.co\nSubject: [UP102EASTDB-SERVER] is Running Out Of Space '$usep'%\n\n/' | /usr/sbin/sendmail -t
    exit 1
    fi
    done


