#!/bin/sh
echo  v3.50 made on bill.merit.edu at Tue Sep 01 15:40:28 EDT 1992
#
#	nsfnett3 Rover Startup Script Source
#
#		This file is machine generated - do not edit 
#
#
# @wbn  02/03/92        Modified startup to use a pid File mechanism rather
#                       than a ps aux | grep Process mechanism to assure
#                       daemon is not already running. (Linda Suggestion)
#
#	Do this command periodically to update network picture:
#
#
#
TZ=CUT0		#Assure logs are in Central Universal Time
export TZ
autokill=YES
PINGKYDIR=/usr/local/rover/data/InetRover
#PINGKYDIR=/rtdata/rover/logs/InetRover
export PINGKYDIR
NETWORK=cicnet
COMMUNITY=monitor
if [ "$DODISCOVERY" = "DODISCOVERY" ]
then
SUBNET=131.103.0.0
SUBNETMASK=255.255.0.0
Discover -c $COMMUNITY -n $NETWORK -r 10 -t 10 -s $SUBNET -m $SUBNETMASK
cat $PINGKYDIR/$NETWORK.LINKS | awk '{ if ( $1==18) print $3" "$8" 0"; if ($1==22) print $3" "$8" 3"}' >$PINGKYDIR/$NETWORK.LinkSpeed.LW
fi

pidFILE="$PINGKYDIR/$NETWORK.pid"
#
#       Assure no other Rover of this type is running in my PINGKYDIR
#
if [ -r $pidFILE ]
then
        ProcessNum=`cat $pidFILE`
        echo '*************************** ERROR ******************************'
        echo '**'" $0  already running:  Apparently Process ID="$ProcessNum
        echo '** ( pid file exists: '$pidFILE' )'
        echo '*************************** ERROR ******************************'
	if [ "$autokill" = "YES" ]
	then
		echo "auto kill is enabled - Killing old $0 process"
        	ps aux | grep -v grep | grep $ProcessNum
		kill $ProcessNum
		echo ""
		echo `date`" SUCCESS: $0 is now starting - old process was killed"
	else
        	echo "Kill This process and restart - Your request is ignored."
        	echo ""
        	exit 1
	fi
fi

echo $$ > $pidFILE 	#Install a Process ID Registration File
#
#	First time through, resolve IP addresses to DNS names
#	Otherwise, we'll leave the IP Addresses as names
#
meritpoller -t $NETWORK -c $COMMUNITY -s $NETWORK.STATUS  -r

while :
do
	( meritpoller -t $NETWORK -c $COMMUNITY -s $NETWORK.STATUS 2>&1 ) >/tmp/$NETWORK.log
	( SortStatus -P CIC_ -s $NETWORK.STATUS 2>&1  ) >/dev/null # >>$PINGKYDIR/rover.log.`day -0`

	if [ -r $PINGKYDIR/$NETWORK.SLEEP ]
	then
		SLEEPTIME=`cat $PINGKYDIR/$NETWORK.SLEEP`
	fi
	if [ "$SLEEPTIME" = "" ]
	then
		SLEEPTIME=100
	fi
	sleep $SLEEPTIME
done
