Hi Monks,

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,

#!/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}; }
Can anyone help me out Please ?

Baiul.


In reply to Sorting Cisco IP accounting data! by Baiul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.