Annotation of coherent/g/usr/lib/uucp/tay104/contrib/uutraf, revision 1.1

1.1     ! root        1: #!/usr/local/bin/perl
        !             2: # uutraf.pl -- UUCP Traffic Analyzer
        !             3: # SCCS Status     : @(#)@ uutraf       1.7
        !             4: # Author          : Johan Vromans
        !             5: # Created On      : ***
        !             6: # Last Modified By: Johan Vromans
        !             7: # Last Modified On: Wed Feb 26 08:52:56 1992
        !             8: # Update Count    : 4
        !             9: # Status          : OK
        !            10: # Requires:       : Perl V4 or later
        !            11: 
        !            12: # Reads UUCP syslog, and generates a report from it.
        !            13: #
        !            14: # Created by Johan Vromans <[email protected]>
        !            15: # Loosely based on an idea by Greg Hackney ([email protected])
        !            16: 
        !            17: # Usage: uutraf [-taylor|-hdb|-bnu|-bsd] [syslog]
        !            18: 
        !            19: # Logfile formats:
        !            20: #
        !            21: # BSD:
        !            22: #
        !            23: # jv mhres (2/23-5:18) (698818735) received 135 b 2 secs
        !            24: # root mhres (2/23-5:19) (698818742) sent 2365 b 3 secs, Pk: 38, Rxmt: 0
        !            25: #
        !            26: # HDB:
        !            27: #
        !            28: # uunet!uucp M (12/10-09:04:22) (C,16390,1) [ttyXX] <- 2371 / 5.000 secs, \
        !            29: #     474 bytes/sec
        !            30: #
        !            31: # Taylor:
        !            32: #
        !            33: # jv mhres (1992-02-24 20:49:04.06) sent 16234 bytes in 148.780 seconds \
        !            34: #    (109 bytes/sec)
        !            35: # jv mhres (1992-02-24 21:04:05.76) received 449 bytes in 6.550 seconds \
        !            36: #    (68 bytes/sec)
        !            37: 
        !            38: $uucp_type = "gnu";
        !            39: 
        !            40: %hosts = ();           # hosts seen
        !            41: %bytes_in = ();                # of bytes received from host
        !            42: %bytes_out = ();       # of bytes sent to host
        !            43: %secs_in = ();         # of seconds connect for recving
        !            44: %secs_out = ();                # of seconds connect for sending
        !            45: %files_in = ();                # of input requests
        !            46: %files_out = ();       # of output requests
        !            47: 
        !            48: # read info, break the lines and tally
        !            49: 
        !            50: if ( $ARGV[0] =~ /^-/ ) {
        !            51:     ($uucp_type = substr (shift (@ARGV), 1)) =~ tr/A-Z/a-z/;
        !            52: }
        !            53: 
        !            54: if ( $uucp_type eq "taylor" || $uucp_type eq "gnu" ) {
        !            55:     @ARGV = ("/usr/spool/uucp/Stats") unless $#ARGV >= 0;
        !            56:     $pat = "^[^ ]+ ([^ ]+) \\(([-0-9:\\/ .]+)\\) " .
        !            57:        "(sent|received) (\\d+) bytes in (\\d+)\\.(\\d+) seconds";
        !            58:     $uucp_type = 0;
        !            59:     $recv = "received";
        !            60: }
        !            61: elsif ( $uucp_type eq "hdb" || $uucp_type eq "bnu" ) {
        !            62:     @ARGV = ("/usr/spool/uucp/.Admin/xferstats") unless $#ARGV >= 0;
        !            63:     $pat = "^([^!]+)![^(]+\\(([-0-9:\\/]+)\\).+([<>])-? " .
        !            64:        "(\\d+) \\/ (\\d+)\\.(\\d+) secs";
        !            65:     $uucp_type = 1;
        !            66:     $recv = "<";
        !            67: }
        !            68: elsif ( $uucp_type eq "bsd" || $uucp_type eq "v7" ) {
        !            69:     @ARGV = ("/usr/spool/uucp/SYSLOG") unless $#ARGV >= 0;
        !            70:     $pat = "^[^ ]+ ([^ ]+) \\(([-0-9:\\/]+)\\) \\([^)]+\\) " .
        !            71:        "(sent|received) (\\d+) b (\\d+) secs";
        !            72:     $uucp_type = 2;
        !            73:     $recv = "received";
        !            74: }
        !            75: else {
        !            76:     die ("Unknown UUCP type: $uucp_type\n");
        !            77: }
        !            78: 
        !            79: $garbage = 0;
        !            80: 
        !            81: while ( <> ) {
        !            82:     unless ( /$pat/o ) {
        !            83:        print STDERR "Possible garbage: $_";
        !            84:        if ( $garbage++ > 10 ) {
        !            85:            die ("Too much garbage; wrong UUCP type?\n");
        !            86:        }
        !            87:        next;
        !            88:     }
        !            89: 
        !            90:     # gather timestamps
        !            91:     $last_date = $2;
        !            92:     $first_date = $last_date unless defined $first_date;
        !            93: 
        !            94:     # initialize new hosts
        !            95:     unless ( defined $hosts{$1} ) {
        !            96:        $hosts{$1} = $files_in{$1} = $files_out{$1} =
        !            97:            $bytes_in{$1} = $bytes_out{$1} =
        !            98:                $secs_in{$1} = $secs_out{$1} = 0;
        !            99:     }
        !           100: 
        !           101:     # Taylor and HDB have milliseconds, BSD has not.
        !           102:     $secs = ($uucp_type == 2) ? ($5 + ($5 == 0 ? 0.5 : 0)) : ($5 + $6/1000);
        !           103: 
        !           104:     # tally
        !           105:     if ( $3 eq $recv ) {               # recv
        !           106:        $bytes_in{$1} += $4;
        !           107:        $files_in{$1}++;
        !           108:        $secs_in{$1} += $secs;
        !           109:     }
        !           110:     else {                     # xmit
        !           111:        $bytes_out{$1} += $4;
        !           112:        $files_out{$1}++;
        !           113:        $secs_out{$1} += $secs;
        !           114:     }
        !           115:     $garbage = 0;
        !           116: }
        !           117: 
        !           118: @hosts = keys (%hosts);
        !           119: die ("No info found, stopped\n") if $#hosts < 0;
        !           120: 
        !           121: ################ report section ################
        !           122: 
        !           123: $thishost = &gethostname();
        !           124: $thishost = (defined $thishost) ? "on node $thishost" : "report";
        !           125: 
        !           126: if ( $uucp_type eq 0 ) {       # Taylor UUCP
        !           127:     substr ($first_date, 16) = "";
        !           128:     substr ($last_date, 16) = "";
        !           129: }
        !           130: 
        !           131: format std_head =
        !           132: @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
        !           133: "UUCP traffic $thishost from $first_date to $last_date"
        !           134: 
        !           135: Remote   -----------K-Bytes----------- ----Hours---- --Avg CPS-- --Files--
        !           136:  Host         Recv      Sent     Total   Recv   Sent  Recv  Sent Recv Sent
        !           137: .
        !           138: format std_out =
        !           139: @<<<<<<< @>>>>>>>> @>>>>>>>> @>>>>>>>> @>>>>> @>>>>> @>>>> @>>>> @>>> @>>>
        !           140: $Zhost,   $Zi_bytes, $Zo_bytes, $Zt_bytes, $Zi_hrs, $Zo_hrs, $Zi_acps, $Zo_acps, $Zi_count, $Zo_count
        !           141: .
        !           142: 
        !           143: $^ = "std_head";
        !           144: $~ = "std_out";
        !           145: 
        !           146: &print_dashes ();
        !           147: 
        !           148: reset "T";            # reset totals
        !           149: 
        !           150: foreach $host (@hosts) {
        !           151:   &print_line ($host, $bytes_in{$host}, $bytes_out{$host},
        !           152:                 $secs_in{$host},  $secs_out{$host},
        !           153:                 $files_in{$host}, $files_out{$host});
        !           154: 
        !           155: }
        !           156: 
        !           157: &print_dashes ();
        !           158: &print_line ("Total", $Ti_bytes, $To_bytes,
        !           159:               $Ti_secs, $To_secs, $Ti_count, $To_count);
        !           160: 
        !           161: ################ that's it ################
        !           162: 
        !           163: sub print_line {
        !           164:   reset "Z";           # reset print fields
        !           165:   local ($Zhost,
        !           166:         $Zi_bytes, $Zo_bytes,
        !           167:         $Zi_secs, $Zo_secs,
        !           168:         $Zi_count, $Zo_count) = @_;
        !           169:   $Ti_bytes += $Zi_bytes;
        !           170:   $To_bytes += $Zo_bytes;
        !           171:   $Zt_bytes = $Zi_bytes + $Zo_bytes;
        !           172:   $Tt_bytes += $Zt_bytes;
        !           173:   $Zi_acps = ($Zi_secs > 0) ? sprintf ("%.0f", $Zi_bytes/$Zi_secs) : "0";
        !           174:   $Zo_acps = ($Zo_secs > 0) ? sprintf ("%.0f", $Zo_bytes/$Zo_secs) : "0";
        !           175:   $Zi_bytes = sprintf ("%.1f", $Zi_bytes/1000);
        !           176:   $Zo_bytes = sprintf ("%.1f", $Zo_bytes/1000);
        !           177:   $Zt_bytes = sprintf ("%.1f", $Zt_bytes/1000);
        !           178:   $Zi_hrs = sprintf ("%.1f", $Zi_secs/3600);
        !           179:   $Zo_hrs = sprintf ("%.1f", $Zo_secs/3600);
        !           180:   $Ti_secs += $Zi_secs;
        !           181:   $To_secs += $Zo_secs;
        !           182:   $Ti_count += $Zi_count;
        !           183:   $To_count += $Zo_count;
        !           184:   write;
        !           185: }
        !           186: 
        !           187: sub print_dashes {
        !           188:   $Zhost = $Zi_bytes = $Zo_bytes = $Zt_bytes =
        !           189:     $Zi_hrs = $Zo_hrs = $Zi_acps = $Zo_acps = $Zi_count = $Zo_count =
        !           190:       "------------";
        !           191:   write;
        !           192:   # easy, isn't it?
        !           193: }
        !           194: 
        !           195: ################ missing ################
        !           196: 
        !           197: sub gethostname {
        !           198:   $ENV{"SHELL"} = "/bin/sh";
        !           199:   $try = `uuname -l 2>/dev/null`;
        !           200:   chop $try;
        !           201:   return $+ if $try =~ /^[-.\w]+$/;
        !           202:   return undef;
        !           203: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.