c has asked for the wisdom of the Perl Monks concerning the following question:

I started this thread with very little knowledge of net::snmp. I got some very good feedback and started working on a script that tries to use snmp to issue a 'copy run tftp' on a cisco router.
The script I am toying with is:

#!/usr/bin/perl -w use strict; use Net::SNMP; my $router = "10.8.10.133"; my $community = "secretstring"; my $tftpdir = "/company/configs/"; my $tftpserver = "10.15.145.15"; my $oid = ".1.3.6.1.4.1.9.2.1.55."; $oid = "$oid$tftpserver"; my $s; my $e; ($s, $e) = Net::SNMP->session( -hostname => $router -community => $com +munity ); my @param = qw($oid OCTET_STRING "host.cfg"); $s->set_request(@param); $s->close;

When I run this code, I receive the following errors:

Argument "community" isn't numeric in subtraction (-) at ./tftp.pl lin +e 14. Argument "57.8.10.133" isn't numeric in subtraction (-) at ./tftp.pl l +ine 14. Odd number of elements in hash assignment at /usr/lib/perl5/site_perl/5.6.0/Net/SNMP.pm line 196. Can't call method "set_request" on an undefined value at ./tftp.pl lin +e 20.

I am thinking that I am putting an incorrect ASN.1 value in my @param, but I am not sure. The errors I am seeing seem to imply that they are expecting a numeric value.
Can anyone comment on the right path to correct this?

humbly -c

Replies are listed 'Best First'.
Re: ASN.1 errors with Net::SNMP?
by mugwumpjism (Hermit) on Aug 10, 2001 at 01:33 UTC

    You're missing a comma:

    ($s, $e) = Net::SNMP->session( -hostname => $router,
    ^

    Once you've fixed that error, the second should go away; you could have caught this by checking that the call to the constructor worked.

Re: ASN.1 errors with Net::SNMP?
by traveler (Parson) on Aug 10, 2001 at 01:39 UTC
    Also you don't need the @param as I noted in the other thread, just pass those three values as the arguments to the sub. Remember that an argument list is truly that, a list.

    HTH, --traveler