I have recently been able to have a script log into our cisco routers and execute commands, but I am unable to get the script to log into our 6506/6509/6513 Catalyst switches. I suspect this is a problem with the prompt format after the login. I do see that the script is logging in successfully, but it returns with the following error:
pattern match timed-out at ./backupconfigs.pl line 13
Please note that I've pasted some of this together and it might not all make sense, but this is the (sanitized) code I'm using:
use Net::Telnet::Cisco;
my $backup_host = "172.xx.xx.xx";
my $device = "hostname";
my $type = "switch";
my $ios_version = 12;
my @out;
my $prompt=Voice;
# Login
my $session = Net::Telnet::Cisco->new(Ho
st => '172.xx.xx.xx');
$session->login('loginname
', 'password');
# Enable mode
if ($session->enable("passwor
d") ) {
@output = $session->cmd('show privilege');
print "My privileges: @output\n";
} else {
warn "Can't enable: " . $session->errmsg;
}
# Transfer config by TFTP
if ($type eq "router") {
if ($ios_version >= 12) {
@out = $session->cmd("copy system:/running-config "
. "t
ftp://$backup_host/$device\n\n\n")
;
} elsif ($ios_version >= 11) {
@out = $session->cmd("copy running-config tftp\n$backup_host\n"
. "$device\n");
} elsif ($ios_version >= 10) {
@out = $session->cmd("write net\n$backup_host\n$device
\n\n");
}
} elsif ($type eq "switch") {
@out = $session->cmd("copy system:/running-config "
. "t
ftp://$backup_host/$device\n\n\n")
;
}
$session->close;
What I need to know is how to change what is expected for the prompt in the login function... in this case, the switch simply returns its hostname with no other characters...
Thanks.