Skip to content

Instantly share code, notes, and snippets.

@leihog
Last active June 1, 2016 08:39
Show Gist options
  • Save leihog/15b0c5c3ec48b6fa7ccc9aaca7fb887f to your computer and use it in GitHub Desktop.
Save leihog/15b0c5c3ec48b6fa7ccc9aaca7fb887f to your computer and use it in GitHub Desktop.
Check disk space
#!/bin/bash
MAX=80
EMAIL=email@example.com
HOST=`hostname`
DISKS=`df -h | awk -v max=$MAX 'NR>1 && NF>1 { perc = (NF==5) ? $4 : $5; sub("%","",perc); if (0+perc >= 0+max) print perc"%", $NF }'`
if [ "$DISKS" != "" ]; then
echo -e "Warning we are running out of disk space on $HOST \n$DISKS" | mail -s "Running out of disk space on $HOST" $EMAIL
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment