Skip to content

Instantly share code, notes, and snippets.

@deekayen
Created July 18, 2012 19:10
Show Gist options
  • Save deekayen/3138155 to your computer and use it in GitHub Desktop.
Save deekayen/3138155 to your computer and use it in GitHub Desktop.
Disk space cron monitor for Ubuntu 8.04
#!/bin/bash
ADMIN="[email protected]"
ALERT=95
df -H | grep -vE '^Filesystem|tmpfs|cdrom|varrun|varlock|udev|devshm|boot' | awk '{ print $3 " " $4 " " $5 }' | 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment