Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: SNMP - cont

by Joost (Canon)
on Aug 27, 2004 at 13:17 UTC ( #386354=note: print w/replies, xml ) Need Help??


in reply to SNMP - cont

Please use <code> tags next time. Your code is hardly readable this way.

The problem I can see immediately is that there should be no my in

print my @test1;

Which will either print to a filehandle called "my" or create a new (empty) @test1 array and print that. Either way, it doesn't print anything to STDOUT.

You need

print @test1;

Replies are listed 'Best First'.
Re^2: SNMP - cont
by theroninwins (Friar) on Aug 27, 2004 at 13:20 UTC
    when i change the print my @test1 to print @test1 it doesn't chnage it still does not print the result... I tried that already :-( .
      Doesn't change that print my @test is wrong
        ok here is the code a bit more readable

        #!/usr/bin/perl -w use Net::SNMP; use strict; use warnings; use diagnostics; open IPFILE, "ipfile.txt" or die "Can't get IPs - $!\n"; my $community = 'public'; my $ifIndex = '1.3.6.1.2.1.47.1.1.1.1.6'; #1.3.6.1.2.1.2.2.1.1 + 1.3.6.1.2.1.47.1.1.1.1.12 my $ifDescr = '1.3.6.1.2.1.47.1.1.1.1.11'; #1.3.6.1.2.1.47.1.1.1.1. +13 my $ifDescr2 = '1.3.6.1.2.1.47.1.1.1.1.2'; #1.3.6.1.2.1.47.1.1.1.1. +13 my @test1; my @test2; while ( my $ip = <IPFILE> ) { chomp $ip; print "Got: $ip\n"; + my ( $session, $error ) = Net::SNMP->session( -hostname => $ip, -community => $community, -port => 161 ); my $response; if ( defined( $response = $session->get_table($ifIndex) ) ) { foreach my $index ( values %{$response} ) #values { my $this_desc = "$ifDescr.$index"; my $description; if ( defined( $description = $session->get_request($this_d +esc) ) ) { my @serial = values %{$description}; #open OUT, ">>serlist.txt"; #print OUT @serial; #close OUT; #open (OUT, ">>serlist.txt"); #print keys %{$description}; #print '.......'; #print values %{$description}, "\n"; } } foreach my $index ( values %{$response} ) #values { my $this_desc = "$ifDescr2.$index"; my $description2; if ( defined( $description2 = $session->get_request($this_ +desc) ) ) { my @desc = values %{$description2}; #open OUT, ">>desclist.txt"; #print OUT @desc; #close OUT; #open (FILE, ">>desclist.txt"); #print keys %{$description}; #print '.......'; #print values %{$description2}, "\n"; } } print @test1; } $session->close(); }


        The object is to make a list of the two values the @test1 and the @desc, so i need to get them out to the main prog to print them: test1;desc .

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://386354]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-06-25 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (81 votes). Check out past polls.

    Notices?