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

I am trying to use net::snmp to send a request to a cisco router to have the device tftp is current running config to a remote tftpserver.
I am familiar with the command set for snmpset, and specifically for this use. It is as follows:

snmpset <router> <RW Community String> .1.3.6.1.4.1.9.2.1.55.<tftp +server ip> string <filename>

However, the net::snmp syntax is throwing me a bit. I am not quite certain where to stuff all of the apparent info that snmpset seems to require.

$where = "10.6.21.100 string $tftpfile"; @param = qw($oid SET_REQUEST $where); ($session, $error) = Net::SNMP->session( -hostname => $router -community => $community ); my $response = $session->set_request(@param);

My questions is concerning the @param list. The net::snmp doc shows:

$response = $session->set_request(@oid_type_value);

the oid, i have, but the ASN.1 value for the type field, I am not too clear on, nor the value that I will be sending. I want to say that the "value" field corresponds to the:

<tftp server ip> string <filename>

portion of the snmpset command, however I am not sure how to stuff all of that into a single list value. Plus, near the end of the net::snmp doc, it lists the acceptable "types". I see SET_REQUEST among the EXPORTABLE list, but I am not sure if this is what I want to use or whether or not its ready to use without additional configuration. Your help is appreciated.

humbly -c

Replies are listed 'Best First'.
Re: copy run tftp on cisco router using net::snmp
by traveler (Parson) on Aug 09, 2001 at 19:00 UTC
    I don't have experience with this module, personally, but I may have a need for it soon. Here is an example program using net::snmp: rping. Also, you are sending a string to the router which is of type OCTET_STRING as far as ASN.1 is concerned.

    I am not sure how to stuff all of that into a single list value

    This is just a way to describe the argument list to the sub. It appears that you want:

    $server = "1.2.3.4"; $oid=".1.3.6.1.4.1.9.2.1.55.$server"; $session->set_request($oid, OCTET_STRING, "myfile");
    HTH, --traveler
Re: copy run tftp on cisco router using net::snmp
by perlmangle (Initiate) on Aug 09, 2001 at 15:38 UTC
    I know this isn't your question, but you can accomplish the same task with Net::Telnet. Here's a script:
    #!/usr/bin/perl use Net::Telnet; my $dow = `date '+%w' --date '1 days ago'`; my $router = "IP_OF_ROUTER"; my $user = "username"; my $pass = "password"; my $enable = "enable_password"; my $tftp_server = "IP_OF_SERVER"; my $t = new Net::Telnet(Timeout => 10); $t->open( $router ); $t->waitfor( '/Username:/' ); $t->print( "$user" ); sleep 2; $t->waitfor( '/Password:/' ); $t->print( "$pass" ); sleep 2; $t->print( "enable" ); $t->waitfor( '/Password:/' ); $t->print( "$enable" ); sleep 2; $t->print( "copy startup-config tftp" ); sleep 2; $t->print( "$tftp_server" ); sleep 2; $t->print( "router.$dow" ); sleep 3; $t->print( "quit" ); exit( 0 );
      Thanks, however, I will not have access to the router via telnet. Our environment uses tacacs, and the systems group will not add a generic user that can be used via the script for login purposes to perform the wr net. Which leaves me with my only alternative. Taking advantage of the RW snmp string on the routers and getting the information through that method. I could certainly use my login/password pair for access, however, I'd like this script to survive whether or not I am with the company of not.
      Thanks for the suggestion and your time spent writing the alternative script, however I'm locked into using net::snmp.

      humbly -c