CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
script to backup a Cisco switch config to TFTP

 



TheBigAmbulance
Novice

Jun 25, 2010, 3:14 PM

Post #1 of 2 (1690 views)
script to backup a Cisco switch config to TFTP Can't Post

I'm trying to write a script that will log into a Cisco switch and copy it's config to a tftp server. What I'm struggling with is that some of the commands have special characters.

For example, here is how it would normally be done:


Code
noc#copy run tftp 
Address or name of remote host []? 10.1.1.1
Destination filename [running-config]? noc.config
!!
4199 bytes copied in 0.920 secs
noc#


Here is my script:

Code
#!/usr/bin/perl 

use Net::Telnet;

my $user = "back";
my $pass = "back";
my $enable = "pass";
my $tftp = '10.1.1.1';
my $device = '10.2.1.1';

use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die');
$telnet->open($device);
$telnet->waitfor('/Username: $/i');
$telnet->print($user);
$telnet->waitfor('/Password: $/i');
$telnet->print($pass);
$telnet->waitfor('/noc.$/i');
$telnet->print('en');
$telnet->waitfor('/Password: $/i');
$telnet->print($password);
print ("WAIT1\n");
$telnet->waitfor('/noc.$/i');
print ("WAIT2\n");
$telnet->print('copy run tftp');
print ("WAIT3\n");
$telnet->waitfor('/Address or name of remote host []? $/i');
print ("WAIT4\n");
$telnet->print($tftp);
print ("WAIT5\n");
$telnet->waitfor('/Destination filename [running-config]? $/i');
print ("WAIT6\n");
$telnet->print('noc.config');


I'm fairly certain it's the "[", "]" and "?" that is messing with me as perl interprets those as something special. I even have placed a "\" at the lead of each of them, but I'm still getting "pattern match timed-out at script.pl line 27". Net::Telnet is doing exactly what's it's supposed to do. No problems with that.

Any Ideas?


Bianca
User

Jun 28, 2010, 1:02 AM

Post #2 of 2 (1647 views)
Re: [TheBigAmbulance] script to backup a Cisco switch config to TFTP [In reply to] Can't Post

Please read http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm

Specially part http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm#What_To_Know_Before_Using

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives