#!/bin/bash # $Id: fsusage 470 2004-12-09 16:56:11Z agriffis $ # # Copyright 2004 Aron Griffis # Released under the GNU GPL v2 # # fsusage: check filesystem usage and issue a warning to syslog if necessary # PATH=/usr/bin:/bin:/usr/sbin:/sbin # percentage to warn at; defaults to 90 warnlevel=${1:-90} # persistent storage area fsudir=/var/lib/fsusage # logging function log() { logger -p local0.alert -t fsusage -- "$1" } mkdir -p $fsudir || { log "failed to create $fsudir" exit 1 } # check local filesystems only df -lh | grep '^/' | while read l; do set -- $l fs=$1 total=$2 used=$3 pct=${5%\%} mnt=$6 statefile=$fsudir/usage${fs//\//_} if [[ $mnt == /mnt/* ]]; then continue fi if [[ $pct -eq 100 ]]; then log "warning: $mnt is RED at $pct% ($used of $total used)" echo $pct > $statefile elif [[ $pct -ge $warnlevel ]]; then log "warning: $mnt is YELLOW at $pct% ($used of $total used)" echo $pct > $statefile elif [[ -r $statefile && $(<$statefile) -ge $warnlevel ]]; then log "info: $mnt is GREEN at $pct% ($used of $total used)" rm -f $statefile fi done