This is just a generic idea.
Code:
#!/bin/sh --
# /etc/cron.hourly/diskusage.cron
# Error out
set -e
# Percentage threshold:
THRESH="75"
# E-mail recipient:
RECIPIENT="root@localhost"
# Tempfile location:
TEMPF="/dev/shm/diskusage.cron.$$"
# Make a report:
( /bin/df -mh 2>/dev/null | grep ^/ | while read partition size used available percentage mountpoint; do
[ ${percentage//\%/} -ge $THRESH ] && echo "$mountpoint full $percentage"; done | column -t ) > "$TEMPF"
# If it contains stuff send it off:
if [ -s "$TEMPF" ]; then
cat "$TEMPF" | mail -s "${HOSTNAME} [WARN] (${THRESH}%)" $RECIPIENT
fi; rm -f "$TEMPF"
exit 0
Using something like Monit would make things more efficient since it's faster more versatile.
BTW I'd be against automagical deletion, unless it's a tempdir.
In that case you don't want a script but run "tmpwatch" instead.
* I've been lazy and used a temporary file for pretty printing instead of an array. Besides that this script doesn't handle exclusions which it should. Aww well.