Last active
February 24, 2016 12:02
-
-
Save Gmanweb/2adde70211c37123df3c to your computer and use it in GitHub Desktop.
Monitor disk space on EC2 instance, send email to alert. Install mail, on CentOS/Redhat: yum install mailx on Ubuntu/Debian yum install mailx. See http://tecadmin.net/bash-mail-command-not-found/#. Create the file in home directory "/home" sudo nano diskSpaceAlert.sh, copy the code below and add your email addresses. change the file permissions …
This file contains hidden or 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/bash | |
| CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g') | |
| THRESHOLD=83 | |
| SERVER=$(ifconfig | perl -nle 's/dr:(\S+)/print $1/e') | |
| EMAILS="emailAddressHere@gmail.com,anotherEmailAddressHere@gmail.com" | |
| if [ "$CURRENT" -gt "$THRESHOLD" ] ; then | |
| mail -s 'Disk Space Alert on ELK-STG' $EMAILS << EOF | |
| Your root partition remaining free space is critically low. Used: $CURRENT% | |
| Please login and clear some space. Elk-Stg-ENV -> $SERVER | |
| EOF | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment