#!/bin/sh

BCNUNOLOG="yes"         # don't show blackouts

#. /usr/local/bcnu/etc/bcnuenv
. $BCNUHOME/agent/agent_head

#set -x
MAXRETRIES=5
RETRIES=0

while [ $RETRIES -lt $MAXRETRIES ]
	do
	if $BCNU -p $BCNUHOST >$BCNUTMP/bcnu-ck 2>&1
	then
		logmsg=`head -1 $BCNUTMP/bcnu-ck`
		echo $STAMP "ok($RETRIES retries) - $logmsg" >>$BCNUHOME/logs/ckbcnu.log
		exit
	else
		RETRIES=`expr $RETRIES + 1`
		sleep 5
	fi
done

# tell us the bad news
echo $STAMP "error($RETRIES retries) - bcnu is not responding" >>$BCNUHOME/logs/ckbcnu.log

for param in $BCNUPARAM
do
	BCNUMSG="$BCNU -m 'error - bcnu is not responding on ($BCNUHOST)' -e $BCNU_ERR $param"
	bcnu_send_now
done
