Skip to content

Instantly share code, notes, and snippets.

@r10r
Created June 12, 2015 09:58
Show Gist options
  • Save r10r/7d9cc0399e354861138d to your computer and use it in GitHub Desktop.
Save r10r/7d9cc0399e354861138d to your computer and use it in GitHub Desktop.
E-Mail alert when disk usage exceeds a configured limit.
#!/bin/bash
LIMIT=95
EMAIL=root
HEAD="$(df -h | head -n1)"
df -h | tail -n+2 | while read part
do
USED=`echo $part | awk '{ print $5 }' | cut -d'%' -f1`
if [ $USED -gt $LIMIT ]; then
name=$(echo $part | awk '{print $6}')
cat | mail -s "$(hostname): low disk space warning" $EMAIL <<EOF
Partition $name reached disk usage limit (${LIMIT}%)
$HEAD
$part
EOF
fi
done
@r10r
Copy link
Author

r10r commented Jun 12, 2015

Use column to align header and partition columns.

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