[net.sources] improved awk scripts for summarizing uucp log files

fred@umcp-cs.UUCP (02/29/84)

Awhile back, Art Zemon <zemon@felix> submitted a couple of awk
scripts for summarizing /usr/spool/uucp/LOGFILE and /usr/spool/uucp/SYSLOG.
<tim@dceim> submitted a script for summarizing the output of the
LOGFILE summarizer script.

I've combined the scripts, and added some features. These scripts
are the result.  Note that under Berkeley Unix they are directly
executable.

==========================================================================
summ_LOGFILE
==========================================================================
#! /bin/awk -f
#
# USEAGE: summ_LOGFILE /usr/spool/uucp/LOGFILE
#
# 14-Dec-83
#
# This script is based on one written by Art Zemon of FileNet Corp.
# It has been modified locally (by Fred Blonder <fred@umcp-cs>) to
# change the output format somewhat, and to sort it into
# alphabetical order by system name.
#
BEGIN		{
			if ( FILENAME == "-" ) {
				print "Useage: summ_LOGFILE <logfile>";
				exit
				}

			no_dev = 0;
		}
$4 ~ /NO/	{
			if ( $6 == "DEVICE)" ) {
				temp = sprintf("%s\t%s", $2, $3);
				if ( nose[no_dev - 1] != temp )
					nose[no_dev++] = temp;
			}
		}

$5 ~ /\(call/	{
			if ( $4 == "SUCCEEDED" )
				++succeed[$7];
			else if ( $4 == "FAILED" )
				++fail[$7];
			else if ( $4 == "LOCKED" )
				++locked[$7];
			else
				print $0
		}

$4 ~ /OK/	{
			if ( $5 == "(startup)" )
				++talk[$2];
			else if ( $5 == "(conversation" )
				++complete[$2];
		}

END		{
			for ( i in succeed )
				list[i] = i;
			for ( i in fail )
				list[i] = i;
			for ( i in locked )
				list[i] = i;
			for ( i in talk )
				list[i] = i;

			printf("UUCP success/failure summary\n\n");
			printf("System   poll  succ fail lock  died\n\n");
			for ( ; ; ) {
				first = "~~~~~~"
				for ( i in list ) {
					if ( list[i] == i && i < first )
						first = i;
				}
				if ( first == "~~~~~~" )
					break;
				i = first;
				list[i] = "";
				if ( ( talk[i] - succeed[i] ) < 0 )
					printf("%-7s    ?  error %3d  %3d  %3d\n", i, fail[i], locked[i], talk[i] - complete[i]);
				else
					printf("%-7s  %3d   %3d  %3d  %3d  %3d\n", i, talk[i] - succeed[i], succeed[i], fail[i], locked[i], talk[i] - complete[i]);
			}
			if ( no_dev > 0 )
				printf("\nNO AVAILABLE DEVICE\n");
				for(i=0; i<no_dev; i++)
					print nose[i];
		}
==========================================================================
summ_SYSLOG
==========================================================================
#! /bin/awk -f
#
# USEAGE: summ_SYSLOG /usr/spool/uucp/SYSLOG
#
# 22-Dec-83
#
# This script is based on one written by Art Zemon of FileNet Corp.
# It has been modified locally (by Fred Blonder <fred@umcp-cs>) to
# change the output format somewhat, and to sort it into
# alphabetical order by system name.
#
BEGIN		{
			if ( FILENAME == "-" ) {
				print "Useage: summ_SYSLOG <syslog>";
				exit
				}

		}
$4 ~ /received/	{
			from[$2] += $6;
			from_time[$2] += $8;
			total_from += $6;
			total_from_time += $8;
			see_saw[$2] += $6
			++users[$1];
		}

$4 ~ /sent/	{
			to[$2] += $6;
			to_time[$2] += $8;
			total_to += $6;
			total_to_time += $8;
			see_saw[$2] -= $6;
			++users[$1];
		}

END		{
			print "Received:"
			print "	system    bytes    time (minutes)\n"
			for ( ; ; ) {
				first = "~~~~~~"
				for ( i in from )
					if ( from[i] != "*" && i < first )
						first = i;
				if ( first == "~~~~~~" )
					break;
				i = first;
				printf("\t%-7s %7d  %6.2f\n", i, from[i], from_time[i] / 60);
				from[i] = "*";
				}
			print "	        -------  ------";
			printf("\tTotals  %7d %7.2f\n", total_from, total_from_time / 60);
			print "\nSent:"
			print "	system    bytes    time (minutes)\n"
			for ( ; ; ) {
				first = "~~~~~~"
				for ( i in to )
					if ( to[i] != "*" && i < first )
						first = i;
				if ( first == "~~~~~~" )
					break;
				i = first;
				printf("\t%-7s %7d  %6.2f\n", i, to[i], to_time[i] / 60);
				to[i] = "*";
				}
			print "	        -------  ------";
			printf("\tTotals  %7d %7.2f\n", total_to, total_to_time / 60);
			print
			print "Balance of bytes ( < 0 means more sent than received)\n"
			for ( ; ; ) {
				first = "~~~~~~"
				for ( i in see_saw )
					if ( see_saw[i] != "*" && i < first )
						first = i;
				if ( first == "~~~~~~" )
					break;
				i = first;
				printf("\t%-7s %7d\n", i, see_saw[i]);
				see_saw[i] = "*";
				}
			print
			print "Messages (by user)\n"
			for ( ; ; ) {
				highest = 0
				for ( i in users )
					if ( users[i] > highest ) {
						highest = users[i];
						first = i;
						}
				if ( highest == 0 )
					break;
				i = first;
				printf("\t%-7s %3d\n", i, users[i]);
				users[i] = "";
				}
			}
==========================================================================

The output of summ_LOGFILE looks like:

	UUCP connection status for 24 hour period ending \
	Wed Feb 29 05:25:41 EST 1984

	UUCP success/failure summary

	System   poll  succ fail lock  died

	aicvax     0     1    0    0    0
	allegra    6     0    2    0    0
	am-vax     ?  error   0    0    0
	aplvax     0     3   11    2    1
	brl-bmd    0     1    0    0    0
	bsos       0    21    4    0    0
	cal-uni    0    13    2    1    2
	cp1        1     0    3    0    0
	cvl        1    35    3    0    4
	dbl        0    24    2    1    0
	eneevax    3    23    3    5    2
	rlgvax     2     2    0    0    0
	seismo     2     9    4    0    1
	wb-chi     0     0   24    0    0

The fields are: number of times you were polled by that system,
number of times you polled that system, unsuccessful attempted
polls, polls which failed due to resources being locked, and number
of times uucico started up, but didn't terminate normally. The
``error'' message indicates that a poll suceeeded in connecting
and logging in, but uucico didn't start up correclty.

					Fred Blonder
					harpo!seismo!umcp-cs!fred