tracking filesystem usage with fsusage

I track filesystem usage on all my home machines using a small script called fsusage, which runs every half-hour from cron. The script queries each local filesystem for usage information via df and compares to state stored in $HOME/.fususage.

If usage is 100% then it issues a RED alert on stdout and to syslog. If usage is >=90% then it issues YELLOW alert on stdout and to syslog. If usage is <90% then it issues a GREEN alert on stdout and to syslog, but only if the previous level was non-GREEN.

The easiest way to get this information in email is to loop on the output lines in cron, as follows. NB: Line continuations don't work in crontab, they're only for presentation.

*/30 * * * * skel/bin/fsusage | while read x; do \
    printf "From: $HOSTNAME fsusage \nTo: your@email.foo\nSubject: \%s\n" "$x" \
    | sendmail -t; done
Filename Date Size MD5
fsusage 09-Dec-2004 08:56 1.2K 4d352e60d0671b31f56f4f06d5d8d8b7

This page was generated Mon Feb 1 11:20:18 2010.