I am trying to simply telnet to a switch and copy a new config file from a tftp server, then reboot the switch. I have read the documentation for Net::Telnet and Net::Telnet::Cisco. It doesn't seem to be that difficult in theory, but in practice I'm not getting the results I'm after. My output file shows that the commands were entered properly, but I don't see that my tftp server was accessed. I've performed these tasks manually to verify IP connectivity, and it worked fine. My code below currently is set for use of Net::Telnet::Cisco. But you'll also notice the pairs of 'waitfor' and 'print' from Net::Telnet. Neither configurations worked for me. The top of the script was verification that my match regexes were correct, as I've read that where most of these scripts fail is timeouts waiting to match a prompt. Regards, Scott
#!c:/Perl/bin/perl use strict; use warnings; use Net::Telnet::Cisco; #Switch#copy tftp start my $string1 = "Address or name of remote host []?"; my $string2 = "Source filename []?"; my $string3 = "Destination filename [startup-config]?"; #Accessing tftp://192.168.1.2/ap_config... #%Error opening tftp://192.168.1.2/ap_config (Timed out) my $string4 = "Switch#"; if ($string1 =~ /Address or name of remote host.*$/) { #print "String 1 matches.\n"; } else { #print "String 1 does not match.\n"; } if ($string2 =~ /Source filename.*$/) { #print "String 2 matches.\n"; } else { #print "String 2 does not match.\n"; } if ($string3 =~ /Destination filename.*$/) { #print "String 3 matches.\n"; } else { #print "String 3 does not match.\n"; } if ($string4 =~ /Switch#/) { #print "String 4 matches.\n"; } else { #print "String 4 does not match.\n"; } my $switch = "192.168.1.2"; my $tftp_server = "192.168.1.101"; my $config_file = "switch-confg"; my $dest_file = "startup-config"; my $user = "Cisco"; my $pass = "Cisco"; my $session = Net::Telnet::Cisco->new( Host => $switch, Input_log => "input.log", Output_log => "output.log", Timeout => 10); $session->waitfor_pause(0.6); $session->always_waitfor_prompt; my @out = $session->open($switch); # Wait for the username prompt and enter username #@out = $session->waitfor('/Username:.*$/'); #@out = $session->print($user); # Wait for the password prompt and enter the password @out = $session->waitfor('/Password:.*$/'); #print @out; @out = $session->print($pass); #print @out; @out = $session->cmd("copy tftp start\n$tftp_server\n$config_file\n$de +st_file\n"); #print @out; #@out = $session->waitfor('/Address or name of remote host.*$/'); #print @out; #@out = $session->print("$tftp_server\n"); #print @out; #@out = $session->waitfor('/Source filename.*$/'); #print @out; #@out = $session->print($config_file . "\n"); #print @out; #@out = $session->waitfor('/Destination filename.*$/'); #print @out; #@out = $session->print($dest_file . "\n"); #print @out; @out = $session->cmd("reload\n\n"); @out = $session->close;

In reply to Cisco Switch by spickles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.