From: fitz@wang.com (Tom Fitzgerald)
Newsgroups: biz.sco.general
Subject: Re: montoring uucp connect time
Date: 28 Jan 93 06:37:06 GMT
Organization: Wang Labs, Lowell MA, USA

frankb@eplegal.UUCP (Frank Brock) writes:

> we are using sco 3.2.4.  i am trying to monitor the length of time
> each uucp connection is made to each machine.

Here's a quick-n-dirty perl script to do it.  It produces output that
looks like

 ailanth  1/22  18:38:46  0:00:35 [3m->1m]       tty1C  incoming
 ailanth  1/23   2:32:11  0:01:39 [3m->1m1n]     tty1C  incoming
 ailanth  1/23  14:33:59  0:00:27 [1m->]         tty1C  incoming

 aragorn  1/23   9:35:38  0:00:07 [->1m]         tty2B  incoming
 aragorn  1/23  11:08:24  0:00:32 [1m->]         tty2A

  bu.edu  1/22  20:41:00  0:00:09 [1n->]         tty1A
  bu.edu  1/23   0:40:56  0:00:09 [1n->]         tty1A
  bu.edu  1/23   2:40:55  0:00:22 [1n->]         tty1A

  e-tech  1/22  21:34:46  0:00:04 [->1m]         tty1C  incoming
  e-tech  1/23   7:33:57  0:07:24 [1m10n->3m]    tty1C  incoming  FAILED

etc.  Columns are system name, date, time, duration, number of mailmessages
(m) and news batches (n) (outgoing->incoming), tty, direction of call and
notes about abnormal termination.

============================= Script follows =============================

#!/usr/local/bin/perl
#
# acctime [-amnio] system1 system2 ....
#
# Prints length of time of each UUCP connection.  If no systems are
# specified, prints connections to all systems for which uucico logfiles
# exist.
#
# Options:
#	-a	Mention all connections, no matter how short.  By default
#		connections lasting less than 4 seconds are not shown.
#	-m	Only show connections in which mail was transferred
#	-n	Only show connections in which news was transferred
#	-i	Only show connections in which files were transferred in
#	-o	Only show connections in which files were transferred out
#
# Written by Tom Fitzgerald <fitz@wang.com>
#
# This program most likely contains several bugs.
#
eval "exec /usr/local/bin/perl -S $0 $*"
	if $running_under_some_shell;

($mailonly, $newsonly, $inonly, $outonly) = (0, 0, 0, 0);
($alllines) = (0);

$| = 1;
$threshhold = 4;

chdir "/usr/spool/uucp/.Log/uucico";

@list = @ARGV;
if (grep (!/^-./, @list) == 0) {
	push (@list, <*>);
}

sub spitline {
	local ($msg) = @_;

	$interval = $secs - $ssecs;
	$interval += 3600*24 if $interval < 0;
	return if $interval < $threshhold && !$alllines;
	$hrs = int ($interval / 3600);
	$min = int ($interval / 60) % 60;
	$sec = $interval % 60;
	$countstr = "["
	  . ($outmail > 0 && !$newsonly && !$inonly
	      ? sprintf ("%dm", $outmail / 2) : '')
	  . ($outnews > 0 && !$mailonly && !$inonly
	      ? sprintf ("%dn", $outnews / 2) : '')
	  . "->"
	  . ($inmail > 0 && !$newsonly && !$outonly
	      ? sprintf ("%dm", $inmail / 2) : '')
	  . ($innews > 0 && !$mailonly && !$outonly
	      ? sprintf ("%dn", $innews / 2) : '')
	  . "]";
	printf "%8s %5s  %8s %2d:%02d:%02d %-14s",
	  $system, $sdate, $stime, $hrs, $min, $sec,
	  $countstr;
	printf "%6s", $tty;
	if (!$outgoing) {
		print "  incoming";
	}
	print "  FAILED"	if /^FAILED/;
	print "  INTERRUPTED"	if /SIGNAL/;
	print "  NO SPACE"	if /create temp/;
	print "  [$msg]"	if $msg;
	print "\n";
}


for $system (@list) {
	if ($system =~ /^-./) {
		$_ = $system;
		$newsonly = !$newsonly if /n/;
		$mailonly = !$mailonly if /m/;
		$inonly   = !$inonly   if /i/;
		$outonly  = !$outonly  if /o/;
		$alllines = !$alllines if /a/;
		next;
	} else {
		open (LOG, $system) || die "Can't open logfile";
	}
	($outgoing, $talking, $first) = (0, 0, 1);
	($inmail, $innews, $outmail, $outnews) = (0, 0, 0, 0);
	while ($line = <LOG>) {
		chop;
		($g1, $name, $g2, $stamp, $_) = split (/ /, $line, 5);
		print "Name mismatch - $name found in $system\n"
		  if !($name eq $system || $system eq '-');
		($date, $time) = ($stamp =~ /\((.*)-([0-9:]*),.*\)/);
		@tf = split (/:/, $time);
		$secs = 3600 * $tf [0] + 60 * $tf [1] + $tf [2];

		if (/^REQUEST /) {
			if (/\(news\)/) {
				++$outnews;
			} else {
				++$outmail;
			}
		} elsif (/^REMOTE REQUESTED/) {
			if (/\(news\)/) {
				++$innews;
			} else {
				++$inmail;
			}
		} elsif (/^SUCCEEDED /) {
			($outgoing, $first) = (1, 0);
			($inmail, $innews, $outmail, $outnews) = (0, 0, 0, 0);
			next;
		}
		if (/^OK \(startup /) {
			if ($talking) {
				&spitline ("missing end");
			}
			($talking, $sdate, $stime, $ssecs, $first)
			  = (1, $date, $time, $secs, 0);
			($inmail, $innews, $outmail, $outnews) = (0, 0, 0, 0);
			($tty) = /startup (tty.*)\)/;
		} elsif (/LOGIN FAILED /) {
			$outgoing = 0;
		} elsif (/conversation|SIGNAL|create temp|startup/) {
			next unless $talking;
			&spitline ('');
			($talking, $outgoing, $first) = (0, 0, 0);
		}
	}
	if ($talking) {
		&spitline ("not complete");
	}
	print "\n";
	close LOG;
}
Newsgroups: biz.sco.general