Baiul has asked for the wisdom of the Perl Monks concerning the following question:
I am a total newbie and have so far with help managed
to make a script which logs onto our routers and does
a "sh ip accounting" command. This then logs the
output as follows:
Source Destination Packets Bytes
10.162.140.33 10.3.1.8 38 2455
10.163.64.52 157.172.251.16 391 497020
10.162.132.53 10.53.1.32 84 13000
I have even managed to cut this all down and make it
print out on screen. What I want to do with it now
is sort the data. I can't seem to get this to work
at all. I have added all double to from entries and
I have a list which I want to sort by Bytes size.
Here is what I have so far,
Can anyone help me out Please ?#!/usr/local/bin/perl -w $rep = "/tmp"; $base = "/appli/ipacc"; #@pool = ('lcvt017','lzdg003','lzdg003','lmhg016','lpar1037','lnrk005' +,'lpar640'); @pool = ('lcvt017'); foreach $router (@pool) { $datafile = "$router.txt"; open(INPUT,"$rep/$datafile"); while (<INPUT>) { if (not (/^###.*/)) { ($src, $dst, $packets, $bytes) = split ; $$summary{$src}{$dst} += $bytes; # $ip_src_list{$src}++; $ip_src_list{$src} += $bytes; $ip_dst_list{$dst}++; } } close(INPUT); #printf "%18s %18s %18s\n", "IP Source", "IP Destination", "Total Byte +s"; foreach $ipsrc (keys %ip_src_list) { foreach $ipdst (keys %ip_dst_list) { if ($$summary{$ipsrc}{$ipdst}) { $tt{"$ipsrc -> $ipdst"} = $$summary{$ipsrc}{$i +pdst}; #printf "%18s %18s %18s\n", $ipsrc, $ipdst, $$ +summary{$ipsrc}{$ipdst}; } } } @list_of_keys = keys %tt; foreach $key (sort keys %tt) { printf "%35s %15d\n",$key, $tt{$key}; }
Baiul.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
I'm starting to sound like a broken record . . .
by Fletch (Bishop) on Feb 25, 2002 at 16:15 UTC | |
by lzcd (Pilgrim) on Feb 25, 2002 at 23:18 UTC | |
|
Re: Sorting Cisco IP accounting data!
by zengargoyle (Deacon) on Feb 26, 2002 at 00:46 UTC | |
by Baiul (Acolyte) on Feb 26, 2002 at 10:39 UTC | |
by zengargoyle (Deacon) on Feb 26, 2002 at 19:07 UTC | |
by zengargoyle (Deacon) on Feb 26, 2002 at 19:15 UTC | |
by Baiul (Acolyte) on Feb 27, 2002 at 09:57 UTC |