#! 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;
In reply to Problem with adding variable from array by Bennco99
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |