spickles has asked for the wisdom of the Perl Monks concerning the following question:
#!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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cisco Switch
by karavelov (Monk) on Jul 19, 2008 at 15:55 UTC |