#!/bin/csh  -f
#
# $Header: /nocol/src/utility/RCS/keepalive_monitors,v 1.3 1992/06/16 18:42:22 aggarwal Exp $
#
# Make sure that the various nocol programs are doing their job and are
# not dead.
#
# Can run this from the crontab every so often/
#
# THE MONITORING PRGRAMS CANNOT HAVE ANY COMMAND LINE ARGS. CREATE
# A SHELL SCRIPT WITH THE ARGS IF NEEDED (e.g. trapmon -n -> trapmon.sh)
#
# Vikas, Nov 30, 1989
#
umask 002

set BIN = /nocol/bin
set OPS = noc@nisc.jvnc.net		# mail on restarting
set MAIL = /usr/ucb/mail
set PROGRAMS = ""			# initially null
set path = (${BIN} /bin /etc /usr/bin /usr/ucb /usr/lib)
set HOST = `hostname`

if ( ${HOST} == "mickey.jvnc.net" ) then
	set PROGRAMS = "trapmon.sh"		# frontend to trapmon options
else if ( ${HOST} == "minnie.jvnc.net" ) then
	set PROGRAMS = "ippingmon nsmon tpmon"
endif

cd $BIN

## Account for the programs that have a pid file, and those that don't.
#
foreach p ( ${PROGRAMS}  )
	set START = "0"		#initial value

	if ( -e ${p}.pid ) then
		set pid = `head -1 ${p}.pid`
		if ( `ps ${pid} | wc -l` == 1 && -x $p ) set START = "1"
	else

		set lc = `ps -ax |egrep "${BIN}/${p}" |grep -v grep`
		if ( "$lc" == "" && -x $p ) set START = "1"
	endif


	if ( ${START} == "1" ) then
		if( $?prompt ) echo "Starting $p"
		( ${BIN}/${p} ) &
		echo " -keepalive" |${MAIL} -s "NOCOL Restarted ${p} on ${HOST}" $OPS
	endif

end

####
