-
-
Save dovideh/3835606 to your computer and use it in GitHub Desktop.
Send email to when disk is below a limit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#The limit is 30% now | |
limit=10 | |
[email protected] | |
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