$uucp_type = "gnu";
%hosts = (); %bytes_in = (); %bytes_out = (); %secs_in = (); %secs_out = (); %files_in = (); %files_out = ();
if ( $ARGV[0] =~ /^-/ ) {
($uucp_type = substr (shift (@ARGV), 1)) =~ tr/A-Z/a-z/;
}
if ( $uucp_type eq "taylor" || $uucp_type eq "gnu" ) {
@ARGV = ("/usr/local/spool/uucp/Stats") unless $ $pat = "^[^ ]+ ([^ ]+) \\(([-0-9:\\/ .]+)\\) " .
"(sent|received) (\\d+) bytes in (\\d+)\\.(\\d+) seconds";
$uucp_type = 0;
$recv = "received";
}
elsif ( $uucp_type eq "hdb" || $uucp_type eq "bnu" ) {
@ARGV = ("/usr/spool/uucp/.Admin/xferstats") unless $ $pat = "^([^!]+)![^(]+\\(([-0-9:\\/]+)\\).+([<>])-? " .
"(\\d+) \\/ (\\d+)\\.(\\d+) secs";
$uucp_type = 1;
$recv = "<";
}
elsif ( $uucp_type eq "bsd" || $uucp_type eq "v7" ) {
@ARGV = ("/usr/spool/uucp/SYSLOG") unless $ $pat = "^[^ ]+ ([^ ]+) \\(([-0-9:\\/]+)\\) \\([^)]+\\) " .
"(sent|received) (\\d+) b (\\d+) secs";
$uucp_type = 2;
$recv = "received";
}
else {
die ("FATAL: Unknown UUCP type: $uucp_type\n");
}
$garbage = 0;
while ( <> ) {
unless ( /$pat/o ) {
print STDERR "$_";
next if /failed/;
if ( $garbage++ > 10 ) {
die ("FATAL: Too much garbage; wrong UUCP type?\n");
}
next;
}
$last_date = $2;
$first_date = $last_date unless defined $first_date;
unless ( defined $hosts{$1} ) {
$hosts{$1} = $files_in{$1} = $files_out{$1} =
$bytes_in{$1} = $bytes_out{$1} =
$secs_in{$1} = $secs_out{$1} = 0;
}
$secs = ($uucp_type == 2) ? ($5 + ($5 == 0 ? 0.5 : 0)) : ($5 + $6/1000);
if ( $3 eq $recv ) { $bytes_in{$1} += $4;
$files_in{$1}++;
$secs_in{$1} += $secs;
}
else { $bytes_out{$1} += $4;
$files_out{$1}++;
$secs_out{$1} += $secs;
}
$garbage = 0;
}
@hosts = keys (%hosts);
die ("No info found, stopped\n") if $
$thishost = &gethostname();
$thishost = (defined $thishost) ? "on node $thishost" : "report";
if ( $uucp_type eq 0 ) { substr ($first_date, 16) = "";
substr ($last_date, 16) = "";
}
format std_head =
@|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"UUCP traffic $thishost from $first_date to $last_date"
Remote -----------K-Bytes----------- ----Hours---- --Avg CPS-- --Files--
Host Recv Sent Total Recv Sent Recv Sent Recv Sent
.
format std_out =
@<<<<<<< @>>>>>>>> @>>>>>>>> @>>>>>>>> @>>>>> @>>>>> @>>>> @>>>> @>>> @>>>
$Zhost, $Zi_bytes, $Zo_bytes, $Zt_bytes, $Zi_hrs, $Zo_hrs, $Zi_acps, $Zo_acps, $Zi_count, $Zo_count
.
$^ = "std_head";
$~ = "std_out";
&print_dashes ();
reset "T";
foreach $host (@hosts) {
&print_line ($host, $bytes_in{$host}, $bytes_out{$host},
$secs_in{$host}, $secs_out{$host},
$files_in{$host}, $files_out{$host});
}
&print_dashes ();
&print_line ("Total", $Ti_bytes, $To_bytes,
$Ti_secs, $To_secs, $Ti_count, $To_count);
sub print_line {
reset "Z"; local ($Zhost,
$Zi_bytes, $Zo_bytes,
$Zi_secs, $Zo_secs,
$Zi_count, $Zo_count) = @_;
$Ti_bytes += $Zi_bytes;
$To_bytes += $Zo_bytes;
$Zt_bytes = $Zi_bytes + $Zo_bytes;
$Tt_bytes += $Zt_bytes;
$Zi_acps = ($Zi_secs > 0) ? sprintf ("%.0f", $Zi_bytes/$Zi_secs) : "0";
$Zo_acps = ($Zo_secs > 0) ? sprintf ("%.0f", $Zo_bytes/$Zo_secs) : "0";
$Zi_bytes = sprintf ("%.1f", $Zi_bytes/1000);
$Zo_bytes = sprintf ("%.1f", $Zo_bytes/1000);
$Zt_bytes = sprintf ("%.1f", $Zt_bytes/1000);
$Zi_hrs = sprintf ("%.1f", $Zi_secs/3600);
$Zo_hrs = sprintf ("%.1f", $Zo_secs/3600);
$Ti_secs += $Zi_secs;
$To_secs += $Zo_secs;
$Ti_count += $Zi_count;
$To_count += $Zo_count;
write;
}
sub print_dashes {
$Zhost = $Zi_bytes = $Zo_bytes = $Zt_bytes =
$Zi_hrs = $Zo_hrs = $Zi_acps = $Zo_acps = $Zi_count = $Zo_count =
"------------";
write;
}
sub gethostname {
$ENV{"SHELL"} = "/bin/sh";
$try = `(hostname) 2>/dev/null`;
chop $try;
return $+ if $try =~ /^[-.\w]+$/;
$try = `uname -n 2>/dev/null`;
chop $try;
return $+ if $try =~ /^[-.\w]+$/;
$try = `uuname -l 2>/dev/null`;
chop $try;
return $+ if $try =~ /^[-.\w]+$/;
return undef;
}