#!/usr/bin/ksh
# Written By	: Kynan Dent
# Written On	: 18/08/2004
# Function		: Watch various things on a machine including:
#               - snoop the interface
#               - vmstat every 5 seconds
#               - check how many sendmail processes are running every 5 seconds
#               - check the depth of the mail queue every 5 seconds

STOPFILE=/var/kynan/stop
DATE=`date +%y%m%d-%H%M`
OUTFILE=/var/kynan/$DATE

[ -f /var/kynan/stop ] && rm /var/kynan/stop

MSG="Started at `date`"
echo $MSG>>${OUTFILE}-vmstat
echo $MSG>>${OUTFILE}-sendmail
echo $MSG>>${OUTFILE}-mailq

vmstat 5 >> ${OUTFILE}-vmstat &
VMSTAT_PROC=$!

snoop  -V -o ${OUTFILE}-snoop &
SNOOP_PROC=$!

while :
do
        if [ -f /var/kynan/stop ]; then
                kill $VMSTAT_PROC
                kill $SNOOP_PROC

                MSG="Finished at `date`"
                echo $MSG>>${OUTFILE}-vmstat
                echo $MSG>>${OUTFILE}-sendmail
                echo $MSG>>${OUTFILE}-mailq
                exit
        else
                echo "sendmail count = "`ps -e | grep -c sendmail` >> ${OUTFILE}-sendmail
                echo "Mail Q = "`mailq | grep To` >> ${OUTFILE}-mailq
                sleep 5
        fi
done