mroe1234 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to use Net::SSH2::Cisco to connect and download config files from Cisco nexus switches. I am suffering from a timeout somewhere. My best guess is that it can't find the prompt again after I execute the command, but I have no idea why. I've been poking at this seemingly simple script for a week now. Any help would be appreciated.
to execute it I do: echo "172.16.2.11,cisco6001 (10G)" | /usr/local/bin/backup_switches.pl
172.16.2.11 is one of our cisco nexus switches
=========The Code===========use Net::SSH2::Cisco; use Getopt::EvaP; use Parallel::ForkManager; use Data::Dumper; my $max_processes = 1; my $tftp_config_directory = "switches/conf/"; my $config_directory = "/srv/tftp/"; my $tftp_server = "192.168.0.206"; my $lp="********"; my $user = "cworker"; my @wd; my $nexus = 'cisco(9372|3048|6001|1000v)'; my $pm = new Parallel::ForkManager($max_processes); while (<>) { @wd = split /,/; my $pid = $pm->start and next; &talkto(@wd); $date = scalar localtime; sleep 1; $pm->finish; } $pm->wait_all_children; sub talkto { local($host,$model) = @_; my $error; my $configfile = $tftp_config_directory . $host . "-confg"; my $sok = Net::SSH2::Cisco->new( host => $host, Dump_Log => '/tmp/backup.log', Output_log => '/tmp/output.log', Input_log => '/tmp/input.log', Waitfor_clear => '0', #as a 0 it doesn't prepend Ctr +l-Z to the command. ); $sok->login(Name =>$user, Password =>$lp, ); my @cmdoutput; my $vrf = 'default'; if ($model =~ /$nexus/) { my $output; @cmdoutput = $sok->cmd( String => "copy startup-config tftp://$tftp_server/$con +figfile vrf $vrf", Errmode => "return", ); print Dumper @cmdoutput; if ($sok->errmsg){ ($error) = $sok->errmsg; print "Nexus IP: $host: Command failed reason: $error. Trying ag +ain...\n" ; @cmdoutput = $sok->cmd( String => "copy startup-config tftp://$tftp_server/$c +onfigfile vrf management", Errmode => "return", ); $sok->waitfor ( String => '#', Timeout => '5', Waitfor_clear => '1', ); print "Output: $output\n"; print Dumper @cmdoutput; print "Nexus IP: $host: Command failed reason: $error\n" ; } } else { @cmdoutput = $sok->cmd( String => "copy running-config tftp $tftp_server $configfile", ); if ($sok->errmsg){ ($error) = $sok->errmsg; print "Catalyst IP: $host Command failed reason: $error"; } } $sok->close; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Net::SSH2::Cisco
by VinsWorldcom (Prior) on Dec 16, 2015 at 19:33 UTC | |
|
Re: Using Net::SSH2::Cisco
by NetWallah (Canon) on Dec 16, 2015 at 19:03 UTC | |
by mroe1234 (Initiate) on Dec 17, 2015 at 17:35 UTC | |
|
Re: Using Net::SSH2::Cisco
by salva (Canon) on Dec 17, 2015 at 18:34 UTC | |
by mroe1234 (Initiate) on Dec 17, 2015 at 19:29 UTC | |
|
Re: Using Net::SSH2::Cisco
by VinsWorldcom (Prior) on Dec 22, 2015 at 17:21 UTC |