Paul -
Karavelov's answer did not work. I wish I knew why. As I said, this shouldn't be that difficult. I can see that all of my commands are being input by viewing the input and output logs. Their contents are as such:
INPUT
User Access Verification
Username: Cisco
Password:
DistrictOffice#copy tftp start
Address or name of remote host []? 172.16.0.100
Source filename []? ACES.cfg
Destination filename startup-config? startup-config
Accessing tftp://172.16.0.100/ACES.cfg...
Loading ACES.cfg from 172.16.0.100 (via GigabitEthernet0/1): !!
OK - 6231 bytes
OK
6231 bytes copied in 9.320 secs (669 bytes/sec)
DistrictOffice#
OUTPUT
Cisco
Cisco
copy tftp start
172.16.0.100
ACES.cfg
startup-config
reload
The fact that my final 'reload' command shows up in my output log and not my input log tells me that the 9 or 10s time for the tftp file to download is where this is breaking. I entered a Prompt variable, but I shouldn't have to since Net::Telnet::Cisco already recognizes most prompts. I also have always_waitfor_prompt, but I'm not sure I've specified it correctly. In other words, is the syntax $session->always_waitfor_prompt all that is necessary?
Current code:
my $session = Net::Telnet::Cisco->new(
Host => $switch,
Prompt => '/.*#/',
Input_log => "input.log",
Output_log => "output.log",
Timeout => 30);
$session->always_waitfor_prompt;
# Wait for the username prompt and enter username
@out = $session->waitfor('/Username:.*$/');
print "@out\n";
@out = $session->print($user);
print "@out\n";
# Wait for the password prompt and enter the password
@out = $session->waitfor('/Password:.*$/');
print "@out\n";
@out = $session->print($password);
print "@out\n";
@out = $session->cmd("copy tftp start\n$tftp_server\n$config_file\n$de
+st_file\n");
print "@out\n";
@out = $session->cmd("reload\n\n");
print "@out\n";
@out = $session->close;
Regards,
Scott
| [reply] [d/l] |
Update: I didn't realize where you were timing out. Try session->waitfor('/#/') after the copy command instead of the sleep. That should avoid issues with a long TFTP copy
Might be a timing\prompt issue. Here's your copy dialog prompt:
DistrictOffice#copy tftp start
Address or name of remote host []? 172.16.0.100
Using session->waitfor('/\?/') might work.
| [reply] |
I put a sleep 20; inbetween the copy command and reload. It seems to work ok...for now.
Scott
| [reply] |
| [reply] |
karavelov -
This is a walled-off garden test lab, so passwords and security for this are default. I have placed on the vty lines privilege level 15 - no need for "enable". I had tried the 'waitfor' with the pound sign, but if you read the docs on Net::Telnet::Cisco, that is a prompt that is already recognized, and default is 'always_waitfor_prompt'. So I don't see how these additions would work. My use of the 'sleep 20' is at the very least reliable and repeatable.
Regards,
Scott
| [reply] |
my $backup_host = "tftpserver.somewhere.net";
my $device = "cisco.somewhere.net";
my $type = "router"; # or "switch";
my $ios_version = 12;
my @out;
if ($type eq "router") {
if ($ios_version >= 12) {
@out = $session->cmd("copy system:/running-config "
. "tftp://$backup_host/$device-confg\n\n\n");
} elsif ($ios_version >= 11) {
@out = $session->cmd("copy running-config tftp\n$backup_host
+\n"
. "$device-confg\n");
} elsif ($ios_version >= 10) {
@out = $session->cmd("write net\n$backup_host\n$device-confg
+\n\n");
}
} elsif ($type eq "switch") {
@out = $session->cmd("copy system:/running-config "
. "tftp://$backup_host/$device-confg\n\n\n");
}
Norman | [reply] [d/l] |