Skip to content

Instantly share code, notes, and snippets.

@deekayen
Created July 18, 2012 19:11
Show Gist options
  • Save deekayen/3138161 to your computer and use it in GitHub Desktop.
Save deekayen/3138161 to your computer and use it in GitHub Desktop.
Disk space cron monitor for Ubuntu
#!/bin/bash
ADMIN="help@example.com"
ALERT=95
df -H | grep -vE '^Filesystem|none|tmpfs|cdrom|varrun|varlock|udev|devshm|boot' | awk '{ print $4 " " $5 " " $6 }' | while read output;
do
usep=$(echo $output | awk '{ print $2}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $3 }' )
free=$(echo $output | awk '{ print $1 }' )
if [[ $usep -ge $ALERT ]]; then
echo "Running out of space $partition ($usep% used, $free avail)
on $(hostname) at $(date)" |
mail -s "Alert: Almost out of disk space $(hostname)" $ADMIN
fi
done
@deekayen
Copy link
Author

Possible crontab to run hourly:

35 * * * * /usr/local/bin/df.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment