Skip to content

Instantly share code, notes, and snippets.

@stefanotorresi
Last active May 25, 2016 13:36
Show Gist options
  • Save stefanotorresi/12302642c9548b61b2cce7a31985a374 to your computer and use it in GitHub Desktop.
Save stefanotorresi/12302642c9548b61b2cce7a31985a374 to your computer and use it in GitHub Desktop.
check disk space left and send email warning
#!/bin/bash
ADMIN="[email protected]"
# set alert-level %
ALERT=85
MAILER=/usr/bin/mail
df -Ph | 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 --fqdn) at $(date)" |
$MAILER -s "Alert: Free space low on $(hostname --fqdn):$partition" $ADMIN
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment