Bennco99 has asked for the wisdom of the Perl Monks concerning the following question:
#! 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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with adding variable from array
by Joost (Canon) on Feb 01, 2007 at 22:41 UTC | |
|
Re: Problem with adding variable from array
by GrandFather (Saint) on Feb 01, 2007 at 22:47 UTC | |
|
Re: Problem with adding variable from array
by Bennco99 (Acolyte) on Feb 01, 2007 at 23:39 UTC | |
by almut (Canon) on Feb 01, 2007 at 23:58 UTC | |
by Bennco99 (Acolyte) on Feb 02, 2007 at 17:14 UTC |