#!/bin/bash

##########################################################################

# Author:                                                                #

#          gfsunny@163.com                                               #

# Create:                                                                #

#          2014/11/14                                                    #

# Function:                                                              #

#          Judge space volume                                            #

# Notes:   You only need to configure Email                              #

##########################################################################

Email="gfsunny@163.com,282750085@qq.com"

Percent=80

DiskSpaceCheck=DSK_`date +%Y_%m_%d`.log

CurrentDate=`date +%Y-%m-%d\ %H:%M:%S\ %A`

#BeforeDayDate=`date -d '1 days ago' +%Y_%m_%d`

DiskUsedTotal=`df -Ph`

for num in `df -Ph | awk '{print $5}' | sed '1d' | tr -d '%'`

do

        df -Ph | sed '1d' | tr -d '%' > tmp.txt

        if [ "$num" -ge "$Percent" ];then

                echo "-------- $CurrentDate -------" > $DiskSpaceCheck

                dir=`cat tmp.txt | awk '$5 >= '"$Percent"'' | awk '{print $6}'`

                echo "${HOSTNAME}:\"$dir\" directory is more than "$Percent"%" >> $DiskSpaceCheck

                echo "$DiskUsedTotal" >> $DiskSpaceCheck

                mail -s "${HOSTNAME}:\"$dir\" directory is more than "$Percent"%" "$Email"< $DiskSpaceCheck

        fi

        rm -f tmp.txt "$DiskSpaceCheck"

done