Cover V02, I03
Article
Listing 1
Listing 2
Sidebar 1

may93.tar


Listing 2: The Sentinel program

###########################################################################
###                                                                     ###
###                              SENTINEL                               ###
###                                     by                              ###
###                                      William Genosa                 ###
###                                                                     ###
### The  Sentinel  program runs on a stable  machine and monitors other ###
### computers on the same  ethernet network  using the  TCP/IP  ruptime ###
### facility to check for a  system crash.   Uucp is utilized to send a ###
### file from the  server to the machine which is running the  Sentinel ###
### program.    This was accomplished by modifying the backup script on ###
### the server.  Absence of this file on the  "Sentinel"  machine is an ###
### indication of backup failure.     When the program detects either a ###
### server has crash or a backup has failed,  it will notify the System ###
### Administrator by calling his  beeper.   Different  codes  allow the ###
### System  Administrator  to determine the problem by seeing the  code ###
### on his beeper.   This program requires the machine running Sentinel ###
### to have a  modem  available for  dialing out,   and for the  System ###
### Administrator to possess a beeper.    The program should be started ###
### in one of the rc scripts.                                           ###
###########################################################################

while true                                   ### Begin infinite while loop.
do

###---------------------- Set up a few variables. -------------------------

HOUR=`date +%H`                              ###  Extract the current hour.
DAY=`date +%a`                               ###  Extract the current  day.

###--------- Test to see if the two main servers are running. -------------

### Cron schedules the two main servers to reboot at 7pm each night. If the
### hour is NOT between  7pm  and  8pm,  test to make sure both servers are
### up and running.   One of the servers is called "cpu5" and the other one
### is called "cpu8".

if [ ${HOUR} -ne 19 ]
then

###--- If cpu5 is down then beep the beeper with code 555-1111. ------

if ruptime | grep "cpu5" | grep "down" > /dev/null
then
cu cpu5down
fi

###--- If cpu8 is down then beep the beeper with code 888-1111. ------

if ruptime | grep "cpu8" | grep "down" > /dev/null
then
cu cpu8down
fi
fi

###------------- Check to see if the backups completed ok. ----------------

### Cron  schedules  backups  on the main  servers  every week  night.  The
### backup scripts test the exit status of  cpio used to create the backup.
### If the backup is successful  (exit status is 0), then the backup script
### sends the file  "backup.ok"  to  cpu4,  the machine where "Sentinel" is
### running.  The servers use "uuto" which place the file in the uucppublic
### directory of machine  cpu4.   Backups  start at  8pm  and finish around
### midnight.

### Since Friday nights backup may not complete till Saturday  morning,  if
### the day is not Sunday, AND if the day is not Monday, AND if the hour is
### 1am,  test to see if the backups completed.

if [ ${DAY} != Sun -a ${DAY} != Mon -a ${HOUR} -eq 1 ]
then

### If  the  file   backup.ok   has  not  arrived  in  the  uucppublic
### directory for  cpu5,  then the  backup  probably failed.  Beep the
### beeper with the code 555-2222.

if [ ! -f /usr/spool/uucppublic/receive/bill/cpu5/backup.ok ]
then
cu badback5
fi

### If  the  file   backup.ok   has  not  arrived  in  the  uucppublic
### directory for  cpu8,  then the  backup  probably failed.  Beep the
### beeper with the code 888-2222.

if [ ! -f /usr/spool/uucppublic/receive/bill/cpu8/backup.ok ]
then
cu badback8
fi
fi

###--------- Remove backup.ok files for the next backup. ------------------

### If it is 3am and the backup.ok files are present in uucppublic for cpu5
### and cpu8,  then we must remove them to prepare for the next backup.

if [ ${HOUR} -eq 3 ]
then
###------- Remove the backup.ok file for cpu5 if it exists. ----------

if [ -f /usr/spool/uucppublic/receive/bill/cpu5/backup.ok ]
then
rm -f   /usr/spool/uucppublic/receive/bill/cpu5/backup.ok
fi

###------- Remove the backup.ok file for cpu8 if it exists. ----------

if [ -f /usr/spool/uucppublic/receive/bill/cpu8/backup.ok ]
then
rm -f   /usr/spool/uucppublic/receive/bill/cpu8/backup.ok
fi
fi

###---------- Sleep ten minutes before making another check. --------------

sleep 600

done