InfoDoc ID   Synopsis   Date
15786   How to log what gets typed at a netcon session   19 Jun 2002

Status Issued

Description
There are occasions where it is useful to know exactly what was typed at a
netcon session, especially if there are multiple administrators and suspected
watchdog resets.

To this end, I have written the following 3 programs and 1 crontab entry:

/etc/rc2.d/S99netcon_logger
===========================
su ssp -c sh <<END_OF_LOGGER >/dev/null
. /etc/opt/SUNWssp/ssp_env.sh
$SSPOPT/bin/netcon_loggerd &
END_OF_LOGGER

/opt/SUNWssp/bin/netcon_loggerd
===============================
#!/bin/sh

while [ `ps -ef | grep netcon_server | grep -v grep | wc -l` = 0 ]
do
    sleep 10
done
for domain in `domain_status | tail +2 | awk '{print $1}'`
do
    SUNW_HOSTNAME=$domain
    export SUNW_HOSTNAME
    netcon < /dev/null 1>>$SSPLOGGER/$domain/netcon.log 2>&1 &
    joblist="$joblist $!"
done
sleep 5
trap 'kill -9 $joblist ; exec $0' 18 1
wait

/opt/SUNWssp/bin/newnetconlog
=============================
#! /usr/bin/sh
#
# Copyright (c) 1998 by Sun Microsystems, Inc.
# All rights reserved.
#

###############################################################################
#
# This script archives netcon.log messages files.  Normally, it should be
# run once per week.  The number of logs to be kept is controlled by
# the shell variable called "MAX" below.
#
###############################################################################
MAX=8

fatal()
{
	echo "ERROR!  $*" >&2
	echo "ABORTING!" >&2
	exit 2
}

ENV=/etc/opt/SUNWssp/ssp_env.sh
[ -f ${ENV} ] || fatal "Couldn't find ${ENV}!"
. ${ENV}

DOM=/var/opt/SUNWssp/.ssp_private/domain_config
[ -f ${DOM} ] || fatal "Couldn't find ${DOM}!"
DOMAINS=`awk -F: '{print $1}' ${DOM}`
LOG=netcon.log

for domain in $DOMAINS
do
	LOGDIR=$SSPLOGGER/$domain
	if [ ! -d $LOGDIR ]
	then
		rm -f $LOGDIR
		mkdir -p $LOGDIR
	fi
	cd $LOGDIR
	i=$MAX
	while [ $i -gt 0 ]
	do
		j=`expr $i - 1`
		test -f ${LOG}.$j && mv -f ${LOG}.$j ${LOG}.$i
		test -f ${LOG}.$j.Z && mv -f ${LOG}.$j.Z ${LOG}.$i.Z
		i=$j
	done
	test -f $LOG && mv -f $LOG ${LOG}.$i
	( sleep 5 ; compress ${LOG}.$i ) &
	touch $LOG
	chown ssp $LOG
	chgrp staff $LOG
done

pid=`/usr/bin/ps -ef | /usr/bin/grep [n]etcon_loggerd | awk '{print $2}'`

if [ "$pid" != "" ]
then
	kill -HUP $pid
else
	sh /etc/rc2.d/S99netcon_logger start
fi

entry to be added to root's crontab
===================================
5 4 * * 6 /opt/SUNWssp/bin/newnetconlog >/dev/null 2>&1 # archives netcon.log


		NOTES
		=====

S99netcon_logger starts netcon_loggerd at boot time.

netcon_loggerd records a log of netcon into a file called netcon.log in the
same directory as the messages files for each domain,
i.e. /var/opt/SUNWssp/adm/<domainname>/netcon.log

If the netcon process which is recording the log dies or is killed,
netcon_loggerd will restart it, unless an exclusive netcon session is used.
To restart recording after an exclusive session has been used, send a
SIGHUP signal to netcon_loggerd,
i.e. kill -HUP <pid-of-netcon_loggerd>
If this is forgotten, then newnetconlog will send the SIGHUP each week anyway.

Finally newnetconlog archives the old log files and compresses them where
possible.      
SUBMITTER: Ken Booth APPLIES TO: Hardware/Ultra Enterprise/Servers/Enterprise 10000, Operating Systems/Solaris/Solaris 2.x ATTACHMENTS:


Copyright (c) 1997-2003 Sun Microsystems, Inc.