I am trying to copy a config to a switch from tftp. Everything works fine if I perform the steps manually, which seems to confirm connectivity, IP address, file name(s), tftp server, etc. However, when I run the script it times out at the command $session->cmd("copy tftp start\n -output omitted"); The error indicates a timeout, but I'm not waiting for any prompt matching, which is the most common reason for timeout. I believe it is timing out while waiting the 9 or 10s for the tftp transfer. I have tried using $session->cmd(String => $string, Timeout => 10) with no luck. Also, using $session->always_waitfor_prompt doesn't help, unless I've implemented it wrong. If I weren't bald already, this would certainly make me pull my hair out b/c this isn't anything difficult. Code below:
############# CONNECT TO THE SWITCH AND UPDATE THE CONFIG FILE #######
+##################################
my $tftp_server = "172.16.0.100";
my $switch = "172.16.1.2";
my $user = "Cisco";
my $password = "Cisco";
my $dest_file = "startup-config";
my $copy_tftp = "copy tftp start\n$tftp_server\n$config_file\n$dest
+_file\n";
#my $matchop = $obj->prompt('/(?m:^\s*--More-- or \(q\)uit/');
# \s matches a whitespace
# \S is a negated \s and matches any non-whitespace character [^\s]
# ? indicates to match 1 or 0 times, and is placed after the characte
+r to match
# ^ indicates to match at the beginning of the line
# $ indicates to match at the end of the line
my $session = Net::Telnet::Cisco->new(
Host => $switch,
Input_log => "input.log",
Output_log => "output.log",
Timeout => 30);
$session->always_waitfor_prompt;
$boolean = $session->ignore_warnings;
$boolean = $session->ignore_warnings($boolean);
# Wait for the username prompt and enter username
@out = $session->waitfor('/Username:.*$/');
print "@out<br>\n";
@out = $session->print($user);
print "@out<br>\n";
# Wait for the password prompt and enter the password
@out = $session->waitfor('/Password:.*$/');
print "@out<br>\n";
@out = $session->print($password);
print "@out<br>\n";
@out = $session->cmd("copy tftp start\n$tftp_server\n$config_file\n$de
+st_file\n");
print "@out<br>\n";
@out = $session->cmd("delete vlan.dat\n\n\n");
print "@out<br>\n";
@out = $session->cmd("reload\n\n");
print "@out<br>\n";
@out = $session->close;
}
Cheers,
Pickles
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.