Skip to content

Instantly share code, notes, and snippets.

@tedheich
Created October 26, 2009 05:42
Show Gist options
  • Save tedheich/218451 to your computer and use it in GitHub Desktop.
Save tedheich/218451 to your computer and use it in GitHub Desktop.
How to check disk level in Linux and mail an alert
ADMIN="adminEmail@yourDomain.com"
# 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
#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=90
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
mail -s 'Disk Space Alert' sysadmin@yourdomain.com << 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