John,
I made many of the changes but what is the addition of the 'next' statement
for? I tried to add the additional code but the script dies mentioning that
it is not terminated correctly. If I comment out the next statement the
script runs fine.
#!/usr/bin/perl
#
use warnings;
use strict;
# Set behaviour
my $log='/var/log/cisco.log';
my $ntop=10;
#chomp ($acl=$ARGV[0]);
#if ($acl eq "") { $acl=".*"};
#chomp ( my $sig = $ARGV[0] || '.*' );
my $acl = $ARGV[ 0 ] || '.*';
open LOG, '<', $log or die "Cannot open '$log' $!";
my ( %srca, %quad, %port, $foo, $moo );
while (<LOG>) {
if (/IPACCESSLOGP: list $acl denied ([tcpud]+)
([0-9.]+)\(([0-9]+)\)\s*->\s*([0-9.]+)\(([0-9]+)\), ([0-9]+) /){
my $x=$6;
$srca{$2}+=$x;
$foo=sprintf("%16s -> %16s %3s port %-6s",$2,$4,$1,$5);
$moo=sprintf("%3s port %-6s",$1,$5);
$quad{$foo}+=$x;
$port{$moo}+=$x;
#next unless /IPACCESSLOGP: list $acl denied ([tcpud]+)
([0-9.]+)\([0-9]+\)\s*->\s*([0-9.]+)\(([0-9]+)\), ([0-9]+) \;
# $srca{ $2 } += $5;
# $quad{ sprintf '%16s -> %16s %3s port %-6s', $2, $3, $1, $4 } += $5;
# $port{ sprintf '%3s port %-6s', $1, $4 } += $5;
}
}
#$n=0;
my $n;
printf "Connection Summary:\n";
foreach my $i (sort { $quad{$b} <=> $quad{$a} } keys %quad) {
if ($n++ >= $ntop) { last };
printf ("%6s:%s\n", $quad{$i},$i);
}
$n=0;
printf "\nDestination Port Summary:\n";
foreach my $i ( sort { $port{$b} <=> $port{$a} } keys %port) {
if ($n++ >= $ntop) { last };
printf ("%6s: %s\n", $port{$i},$i);
}
$n=0;
printf "\nSource Address Summary:\n";
foreach my $i ( sort { $srca{$b} <=> $srca{$a} } keys %srca) {
if ($n++ >= $ntop) { last };
printf ("%6s: %s\n", $srca{$i},$i);
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/