Hi Monks,

I am a novice with Perl which is why I am here :) I have been trying to adapt this Cisco script to collect a bit more info. via SNMP. It normally just collects "Interface, IP-Address, Mask, MTU, Speed, Admin, Operational" and I have added "System Name, Serial Number, System Hardware, Card Description, Card Serial Number".

The problem is if I run it against a router that has 3 IP interfaces and 4 cards/modules I get the 3 IP interfaces and the first 3 of the cards. It misses the last card, I can only guess the interface code is dictating the number of lines to use.

I am sure it is something obvious but it is beyond my current understanding so some help would be greatly appreciated.

Thank you,
Chris

---- Cisco Stats Script ----

#!/usr/bin/perl -w # # $workingdir="/usr/local/scripts/tmp/work"; $snmpro="blah1"; # $rtrlist="$workingdir/RTR_LIST"; $snmpwalk="/usr/local/bin/snmpwalk -v 1 -c $snmpro"; $snmpget="/usr/local/bin/snmpget -v 1 -c $snmpro"; open (RTR, "$rtrlist") || die "Can't open $rtrlist file"; open (CSV, ">$workingdir/RESULT.csv") || die "Can't open RESULT.csv fi +le"; print CSV "Hostname,Interface,IP-Address,Mask,MTU,Speed,Admin,Opera +tional"; while (<RTR>) { chomp($rtr="$_"); @ifIndex=`$snmpwalk $rtr .1.3.6.1.2.1.4.20.1.2`; @ipAddress=`$snmpwalk $rtr .1.3.6.1.2.1.4.20.1.1`; @ipMask=`$snmpwalk $rtr .1.3.6.1.2.1.4.20.1.3`; @cardDescription=`$snmpwalk $rtr enterprises.9.3.6.11.1.3`; @cardSerialN=`$snmpwalk $rtr enterprises.9.3.6.11.1.4`; $arraynum=0; for $ifnumber (@ifIndex) { chomp(($foo, $ifnum) = split(/: /, $ifnumber)); $ifDescription=`$snmpget $rtr ifDescr.$ifnum`; $ifMTU=`$snmpget $rtr ifMtu.$ifnum`; $ifSpeed=`$snmpget $rtr ifSpeed.$ifnum`; $ifAdminstatus=`$snmpget $rtr ifAdminStatus.$ifnum`; $ifOperstatus=`$snmpget $rtr ifOperStatus.$ifnum`; $sysName=`$snmpget $rtr sysName.0`; $sysHware=`$snmpget $rtr sysDescr.0`; $SerialN=`$snmpget $rtr enterprises.9.3.6.3.0`; chomp(($foo, $ipaddr) = split(/: /, $ipAddress[$arraynum])); chomp(($foo, $mask) = split(/: /, $ipMask[$arraynum])); chomp(($foo, $carddes) = split(/: /, $cardDescription[$arraynum] +)); chomp(($foo, $cardsn) = split(/: /, $cardSerialN[$arraynum])); chomp(($foo, $ifdes) = split(/: /, $ifDescription)); chomp(($foo, $mtu) = split (/: /, $ifMTU)); chomp(($foo, $speed) = split (/: /, $ifSpeed)); chomp(($foo, $admin) = split (/: /, $ifAdminstatus)); chomp(($foo, $oper) = split (/: /, $ifOperstatus)); chomp(($foo, $sysname) = split (/: /, $sysName)); chomp(($foo, $syshw) = split (/: /, $sysHware)); chomp(($foo, $sn) = split (/: /, $SerialN)); if ( $speed > 3194967295 ) { $speed = 0 }; $admin =~ s/\(.*\)//; $oper =~ s/\(.*\)//; if ( $oper eq "dormant" ) { $oper = "up(spoofing)"}; $speed = $speed/1000; if ( $speed > 1000) { $speed = $speed/1000; $speed =~ s/$/ Mb\/s/; } else { $speed =~ s/$/ Kb\/s/; } print CSV "\n$sysname,$rtr,$ifdes,$ipaddr,$mask,$mtu,$speed,$adm +in,$oper,$sn,\"$syshw\",$carddes,$cardsn"; $arraynum++; } } close(RTR); close(CSV);

In reply to Array trouble? by chrisric

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.