#!/bin/sh
#
# Script to monitor available filesystem space and to mail alerts when
filesystems become full
#

# Alert recipients (comma separated list)
RECIPIENTS_BCC=
RECIPIENTS_EWETEL=

# welche Verzeichnisse sollen ueberwacht werden
# Beispiel: 'opt|patrol': alle Vorkommen von opt und patrol
FS_EWETEL='opt'

GREP=/usr/xpg4/bin/grep

TMP=/tmp/df_minus_k.$$

trap "rm -f ${TMP}; exit 0" 0 1 2 3 15

case `uname` in
	BSD/OS) DF="df"
		MAIL=mail;;
	*)      DF="df -k"
		MAIL=mailx;;
esac

${DF} | grep "/" | $GREP -E ${FS_EWETEL} | awk '
{
	LIMIT=0.8

	tot=$3+$4
	if ($3 > LIMIT * tot)
	printf "WARNING:  The %s filesystem is at %s capacity !\n",$6,$5
}' >> ${TMP}

if [ -s ${TMP} ]; then
	echo >> ${TMP}
	$DF >> ${TMP}

	${MAIL} -b ${RECIPIENTS_BCC} -s "EWETEL: Diskspace Alert from `uname
-n`" ${RECIPIENTS_EWETEL} < ${TMP}

fi


