#!/bin/sh

/usr/bin/clear

# Create temporary file, will be used to display a message to
# the user upon termination of the telnet session. Message will 
# display the escape sequence that was used to quit telnet.

MSGFILE=`/bin/mktemp /tmp/cmfconsole.XXXXXX`

if [ $? -eq 0 ]
then
	MSGFILE_OPTION="-m $MSGFILE"
else
	MSGFILE_OPTION=
fi

# trap SIGHUP. If the process is halted without exiting telnet,
# for example the user just closes the telnet window, need to cleanup
# the MSGFILE

trap '/bin/rm -rf $MSGFILE 2> /dev/null; exit 1' 1

# Call cmfconsole to establish connection to console via cmfd.
/usr/opt/ams/bin/cmfconsole -c $1 -a $2 -s $3 $MSGFILE_OPTION /usr/bin/telnet

if [ -e "$MSGFILE" ]
then
	/bin/cat $MSGFILE
	/bin/rm $MSGFILE
fi

echo -n "Press <return> to exit "
read stat
