Oh worthy monks, I need help with this script. I have used the base code from the Net::SNMP description from CPAN and have modified it to take an interface index number and via an snmp get, get the interface description.
The script works good if I hard code the node and the interface, but if I try to pull the variables from another source and use the array the script bombs saying "Result ERROR:: No response from remote host 'MyNode'."
#! c:/perl/bin/perl -w use strict; use Net::SNMP; ############################### Declarations ####################### my $now = localtime(); # Time in a readable format my $logfile = "D:/perl_logs/IfIndex2IfDesc.out"; # For Troublesho +oting open (logfile,">>",$logfile) or die "Failed to open IfIndex2IfDesc + log file: $!"; print logfile "\n"; print logfile "************ Start of script :$now ************** +****\n"; #Create an array with the data passed through. Seperate & count indiv +idually my $count = 0; foreach $element (@ARGV) { print logfile "$count,$element\n"; $count += 1; } my $community = "public"; $node = "MyNode"; $interface = "25"; # $node = ("$ARGV[1]"); # $interface = ("$ARGV[3]"); chomp ($node); chomp ($interface); my ($session, $error) = Net::SNMP->session( -hostname => shift || $node, -community => shift || $community ); print logfile "node:'$node'\n"; print logfile "IF:'$interface'\n"; if (!defined($session)) { printf("Session ERROR: %s.\n", $error); exit 1; } my $IfDescr = '.1.3.6.1.2.1.2.2.1.2.'.$interface; my $result = $session->get_request( -varbindlist => [$IfDescr] ); if (!defined($result)) { printf("Result ERROR:: %s.\n", $session->error); $session->close; exit 1; } printf("Interface Description / Alias for host '%s' is '%s'\n", $session->hostname, $result->{$IfDescr} ); print logfile ("Interface Description / Alias for host '$node' is ' +$result->{$IfDescr}'\n", ); print logfile "\n"; $session->close; close logfile; exit 0;

Still a newbie at this and would appreciate the help.
Thank you
JB

In reply to Problem with adding variable from array by Bennco99

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.