Cover V05, I01
Article
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6

jan96.tar


Listing 1: sysmon.sh--the system monitor

#!/bin/sh
#
# sysmon - system monitor.
#
# SYNOPSIS
#    /usr/local/etc/sysmon [init | cont | sked]
#
# DESCRIPTION
#    Maintains downtime/heartbeat/incident logs for calculating avail-
#    ability.  Normally called from cron(8).
#
# OPTIONS
#    init	Emit an incident record (line) to the current daily log
#		file.  Normally called near the end of rc.local to indi-
#		cate the time the system came back to life.  An incident
#		record has the format:
#
#		    - yyyy mm dd hh mn ss
#
#		where:
#		    yyyy  -- year 	(AD)
#		    mm    -- month	(01 - 12)
#		    dd    -- day	(01 - 31)
#		    hh    -- hour	(00 - 23)
#		    mn	  -- minute	(00 - 59)
#		    ss    -- second	(00 - 59)
#
#    cont	Emit a heartbeat record to the current daily log file.
#		This is the default. A heartbeat record has the format:
#
#		    + yyyy mm dd hh mn ss
#
#    sked	Emit a scheduled downtime record:
#
#		    * yyyy mm dd hh mn ss
#
#		Normally,  sysmon isn't called to do this.  After sched-
#		uled downtime,  the sysadmin should edit current daily
#		and insert a "*" for "-" in the last incident record.
#
# FILES
#    Unless otherwise indicated,  all files reside in LOGROOT,  and
#    All temporary files reside in /tmp.
#
#    D.yyyy.mm.dd   --	A daily log.  If yyyy.mm.dd is today's date,
#			the log is active.
#
#	A daily log record has the format documented above (OPTIONS).
#	In addition,  it may contain arbitrary comment lines,  indi-
#	cated by a "type" field of "#".
#
#    M.yyyy.mm      --  A monthly log.
#
#    Y.yyyy	    --  A yearly log.
#
#    sysmon.$$.*    --	Temporary files;  always removed by the script.
#
#    LOKFILE        --  If it exists,  the daily log is locked; no
#			other process should fiddle with them. Its
#			content is the name of the locked file.

# Installation constants
#set -x
HIWATER=5000
LOGDIR=/var/log
LOGROOT=$LOGDIR
LOKFILE=$LOGROOT/sysmon.LOCK
#
# Direct paths to programs used
CUT=/bin/cut
DATE=/bin/date
ECHO=/bin/echo
RM=/bin/rm

#
# Begin.
#

#
# Set the date parameters.
$DATE '+%y %m %d %H %M %S' > /tmp/sysmon.$$.date
YY=`$CUT -d' ' -f1 /tmp/sysmon.$$.date`
MM=`$CUT -d' ' -f2 /tmp/sysmon.$$.date`
DD=`$CUT -d' ' -f3 /tmp/sysmon.$$.date`
HH=`$CUT -d' ' -f4 /tmp/sysmon.$$.date`
MN=`$CUT -d' ' -f5 /tmp/sysmon.$$.date`
SS=`$CUT -d' ' -f6 /tmp/sysmon.$$.date`
$RM -f /tmp/sysmon.$$.*
YY=`expr $YY + 1900`

#
# Do according to command line parameters -- usually
just sets
# the type of record to be emitted.
case "$1"
in
cont)   CC="+"
;;

init)   CC="-"
$RM -f $LOKFILE
;;

sked)   CC='*'
;;

*   )   CC="+"
;;
esac

#
# Set file name.
FN="D.$YY.$MM.$DD"

#
# Attempt to lock.
if  [ -f $LOKFILE ]
then
#
#   File already exists;  something is terribly wrong.  Quit.
exit 1
else
$ECHO "$FN" > $LOKFILE

fi

#
# Emit record.
$ECHO "$CC $YY $MM $DD $HH $MN $SS" >>
$LOGROOT/$FN
$RM -f $LOKFILE

#
# Normal termination
exit 0