Cover V07, I01
Article
Listing 1
Listing 2

jan98.tar


Listing 1: sentry

#!/bin/sh

# This software is copyright by:
# Le Reseau netwerksystemen BV
# Middelstum
# The Netherlands

PATH=/bin:/sbin:/usr/bin:/usr/sbin

SENTRYDIR=${SENTRYDIR:-/usr/local/sentry}
SENTRYLOG=${SENTRYLOG:-/var/log/sentry.log}
SENTRYMAIL=${SENTRYMAIL:-boa@reseau.nl}

export SENTRYDIR

SENTRYLOCK=/tmp/sentry.lock
DATEFMT="%Y%m%d %T"
SEPSTR="====================================================================="

# Exit silently if we're already running. This prevents the logfile from
# getting garbled on heavily loaded systems
Checklock() {
if [ -f $SENTRYLOCK ]; then exit 0; fi
}

# Trap normal and signaled exit
Settraps() {
trap 'rm -f $tmpfile; rm -f $SENTRYLOCK; exit $status' 0
trap 'rm -f $tmpfile; rm -f $SENTRYLOCK; exit 1' 1 2 3 15
}

Procopts() {
while [ $# -gt 0 ]
do
case $1 in
-daily) DAILY=1;;
*) echo "Unknow option $1";;
esac
shift
done
}

Logheader() {
echo; echo
echo $SEPSTR
date +"$DATEFMT"
echo $SEPSTR
uptime
echo
}

Sendmail() {
system=`uname -n`
cat <<ENDMAIL >/tmp/sentry.mail.$$
To: $SENTRYMAIL
Subject: Sentry warning ($1) on $system

=== $1 generated this warning on $system
ENDMAIL

cat $tmpfile >> /tmp/sentry.mail.$$
echo === >> /tmp/sentry.mail.$$

sendmail -t < /tmp/sentry.mail.$$
rm -f /tmp/sentry.mail.$$
}

Dochecks() {
for i in $*
do
chk=`echo $i |sed -e s#.*/##`
echo >> $SENTRYLOG
echo === $chk >> $SENTRYLOG
sh $i > $tmpfile
result=$?
cat $tmpfile >> $SENTRYLOG
if [ $result = 1 ]; then Sendmail $chk; fi
done
}
############
# Main

Checklock

Settraps

touch $SENTRYLOCK

Procopts $*

Logheader >> $SENTRYLOG

tmpfile=/tmp/sentry.out.$$

Dochecks $SENTRYDIR/*.chk

if [ x$DAILY != x ]; then
Dochecks $SENTRYDIR/*.chk.daily
fi

# End of File