Skip to content

Instantly share code, notes, and snippets.

@ovidiucs
Forked from scorpio2k2/gist:3835412
Created October 4, 2012 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovidiucs/3835606 to your computer and use it in GitHub Desktop.
Save ovidiucs/3835606 to your computer and use it in GitHub Desktop.
Send email to when disk is below a limit
#!/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 | awk 'FNR == 2 {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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment