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; }

In reply to Using Net::SSH2::Cisco by mroe1234

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.