Created
October 26, 2009 05:42
-
-
Save tedheich/218451 to your computer and use it in GitHub Desktop.
How to check disk level in Linux and mail an alert
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
ADMIN="[email protected]" | |
# set alert-level 90 % standard | |
ALERT=10 | |
df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output; | |
do | |
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 ) | |
partition=$(echo $output | awk '{ print $2 }' ) | |
if [ $usep -ge $ALERT ]; then | |
echo "space low on \"$partition ($usep%)\", on server $(hostname) at $(date)" | | |
mail -s "Alert: Free space low, $usep % used on $partition" $ADMIN | |
fi | |
done |
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=90 | |
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then | |
mail -s 'Disk Space Alert' [email protected] << EOF | |
Your root partition remaining free space is critically low. Used: $CURRENT% | |
EOF | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment