:
#
# aodnotf (Online Diagnostics)
#


# check for superuser id

if [ `logname` != "root" ]
then
	echo "Must be super-user to execute aodnotf routine"
	exit 1
fi

# preset notification return code (to non-error status).

notified=0

# preset the usage message

USAGE="aodnotf usage: aodnotf -o 'arg' [-hv]"

# determine invocation option(s)
set -- `getopt ho:v $*`
if [ $? != 0 ]
then
	echo $USAGE
	exit 2
fi

for i in $*
do
	case $i in
	-h) HEADINGS="on"; shift;;
	-o) ERRFILE="$2.callfile";REPFILE="report.$2"; shift; shift;;
	-v) VERBOSE="on"; shift;;
	--) shift; break;;
	esac
done

# set working directory to error-logging default

cd /usr/adm/streams

# use -o argument passed to this routine as error reporting file name base

if [ "$ERRFILE" ]
then
	if [ ! -f $ERRFILE ]		# if the file hasn't been created
	then				# notify user of error and exit
		echo "Error threshold reporting file $ERRFILE does not exist"
		exit 4
	fi
else
	echo "Error threshold reporting filename must be passed as argument"
	exit 3
fi

# set up aliases for uu command execution

REMSYSTEM=`awk 'BEGIN{FS="|"}{print $1}' /usr/lib/aod.remsys`
THISSYSTEM=`uuname -l`
DATE=`date`
echo $DATE
MONTH=`echo $DATE | awk '{print $2}'`
DAY=`echo $DATE | awk '{print $3}'`

# start send of file to remote system, save output for status tracking

chmod 644 $ERRFILE

UUJOBID=`uucp -ga -j -m -nroot -x9 -r $ERRFILE $REMSYSTEM"!~/online/"$THISSYSTEM/$MONTH-$DAY/$REPFILE`
echo "$UUJOBID"

# monitor execution of the uucp job until completed

RETRIES=0
until [ $RETRIES -ge 5 ]
do

 	STMP=/tmp/$SYS
	rm -f /tmp/$REMSYSTEM
	> /tmp/$REMSYSTEM  
	chmod 660 /tmp/$REMSYSTEM

	STATUS=/usr/spool/uucp/.Status
        rm -f /usr/spool/uucp/.Status/$REMSYSTEM
	/usr/lib/uucp/uucico -r1 -S$REMSYSTEM  -x1 >/tmp/$REMSYSTEM 2>&1&

	if [ ! "`uustat -a | grep '$UUJOBID'`" ]
	then
		exit 0
	fi

        # wait 2 minutes then check if job is complete
	sleep 120  	
	
	if [ ! "`uustat -a | grep '$UUJOBID'`" ]
	then
		exit 0
	fi
	RETRIES=`expr $RETRIES + 1`
done

exit 1
