i've had problems getting perl to ssh to a Cisco.

it seems that Cisco's sshd is incompatible with Net::SSH::Perl. run both the module and the system ssh in verbose mode and you'll see that N:S:P opens two channels, one for a global-like session or some such, then another for each cmd that is sent. plain ssh only uses only one channel for a shell (or a command). i got far enough down in debugging to see that the first channel autenticates fine, but it seems the Cisco's sshd doesn't support more than a single channel, the second channel created for the cmd fails with some sort of 'out of resource' message.

my current solution is to use Expect and the system ssh command (which works fine).

i'll create a trouble ticket with Cisco for this issue once i pin it down and have some time to try again and take notes. (and make sure i'm not missing something)

this may or may not help...

package NE; use base 'Expect'; # from Net::Telnet::Cisco $prompt = qr/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enab +le\))?\s*$)/; sub cmd { my ( $exp, $cmd ) = @_; $exp->print($cmd, "\n"); $exp->expect( 10, -re => $prompt ) or return; $out = $exp->before; $match = $exp->match; $out =~ s/^$cmd\r?\n//; return $out; } sub login { my ( $exp, $user, $pass ) = @_; $exp->expect( 10, [ qr/[Pp]assword:\s*/, sub { my $exp = shift; $exp->print($pass, "\n"); exp_continue; }], [ qr/[Uu]sername:\s*/, sub { my $exp = shift; $exp->print($user, "\n"); exp_continue; }], -re => $prompt, ); } sub enable { my ( $exp, $pass ) = @_; $exp->print("enable", "\n"); $exp->login( '', $pass ); } package main; #$Expect::Debug = 1; $Expect::Log_Stdout = 0; my $exp = NE->new(); $exp->spawn(qw| /usr/bin/ssh -2 -l admin myrouter |) or die "spawn: $!\n"; $exp->login( '', "******" ); $exp->enable( "**********" ); my ( $out ); $exp->cmd( "terminal length 0" ); ( $out ) = $exp->cmd( "show running-config" ); print $out; $exp->cmd( "exit" ); $exp->soft_close(); exit;

another possibility yet to be investigated is using Net::SSH::Perl for the connection, trying to fish out the filhandle that it creates and pass it to Net::Telnet::Cisco directly and use Net::Telnet::Cisco for the cmd handling. this will probably take some hacking as it looks like the first Net::SSH::Perl channel is opened with different parameters than the channels opened for the commands.

another possibility might be the Web interface. i haven't played with that at all yet.


In reply to Re: How do I connect to cisco pix via ssh? by Anonymous Monk
in thread How do I connect to cisco pix via ssh? by Nalina

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.