Skip to content

Instantly share code, notes, and snippets.

@scorpio2k2
Created October 4, 2012 18:18

Revisions

  1. scorpio2k2 created this gist Oct 4, 2012.
    26 changes: 26 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/bin/sh

    #The limit is 30% now
    limit=10
    mail=contact@debian-tutorials.com
    tmp_file=/tmp/diskusage
    hostname=`hostname`

    #Now the script will calculate the current disk usage
    disk=$(df -h | head -2 | tail -1 | awk '{print $5}' | sed 's/%//')

    #Now the script will compare the current value with the limit
    if [ $(expr $disk ">=" $limit) -ne 0 ]
    then

    echo "Your Disk space limit is set to: $limit %" > $tmp_file
    echo "Occupied space on the server is: $disk %" >> $tmp_file
    echo "Notification!!! Disk Space Usage on server $hostname exceeded the limit." >> $tmp_file
    fi

    #Now we send the notification
    if [ -e $TEMPFILE ]
    then
    mail -s "IMPORTANT!!! Disk Space Notification" $mail < $tmp_file
    fi
    exit 0