Skip to content

Instantly share code, notes, and snippets.

@troygnichols
Created August 7, 2014 20:49
Show Gist options
  • Save troygnichols/bd1cefda609ee32ff9e3 to your computer and use it in GitHub Desktop.
Save troygnichols/bd1cefda609ee32ff9e3 to your computer and use it in GitHub Desktop.
Check disk space, send email when low. Put this in a cron job.
#!/bin/sh
EMAILS=foo@example.com bar@example.com
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while
read output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
parition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 75 ]; then
echo "Disk space low for \"$partition ($usep%)\" on $(hostname) as of $(date)" | mail -s "Alert: Low disk space $usep%" $EMAILS
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment