Xane has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have been trying to get Net::SSH2::Cisco to work on Cisco XR, but seems to fail.
I have the same script working on a Cisco IOS device.
#!/usr/bin/perl use strict; use warnings; use Net::SSH2::Cisco; my $host = Net::SSH2::Cisco->new( Host => 'device', Always_waitfor_prompt => 1, Prompt => '/(?m:^\\s?(?:[\\w.\/]+\:)?(?:[\\w.-]+\@)?[\\w.-]+\\s?(? +:\(config[^\)]*\))?\\s?(?:\(admin-config[^\)]*\))?\\s?[\$#>]\\s?(?:\( +enable\))?\\s*$)/', Input_log => "log/device.log", Output_log => "log/output_device.log", Dump_Log => "log/dump_device", Waitfor_clear => '0', ); $host->login( name => 'user', password => 'pass', ); #$host->cmd("term leng 0"); my @abc = $host->cmd( String => 'sh ver', Prompt => '/(?m:^\\s?(?:[\\w.\/]+\:)?(?:[\\w.-]+\@)?[\\w.-]+\\ +s?(?:\(config[^\)]*\))?\\s?(?:\(admin-config[^\)]*\))?\\s?[\$#>]\\s?( +?:\(enable\))?\\s*$)/', Timeout => '20' ); print @abc; $host->close;
Prompt for Cisco XR:
RP/0/RSP0/CPU0:DEVICE#


Prompt for Cisco IOS:
DEVICE#


Dump file on XR device:
> 0x00000: 73 68 20 76 65 72 0a sh ver.


Dump file on IOS device:
< 0x00000: 64 65 76 69 63 65 23 . .DEVICE#
> 0x00000: 73 68 20 76 65 72 0a sh ver.
< 0x00000: 73 68 20 76 65 72 0d 0a sh ver..


Replies are listed 'Best First'.
Re: Net::SSH2::Cisco not working on Cisco XR
by VinsWorldcom (Prior) on Mar 02, 2016 at 15:13 UTC

    You have the right idea checking dump files. I've had issues with XR also since the prompt is different. That's the main cause of "issues" - the script not finding the prompt. Note I've seen this with Net::Telnet::Cisco too, so it may not be a protocol thing, just simply not matching the prompt.

    I see you've tried a custom prompt. I've had success with this in the past:

    '/(?m:^(?:[\w.\/]+\:)?[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\( +enable\))?\s*$)/'
      Hi VinsWorldcom, Im still being timed out:
      command timed-out at ./ssh.pl line 25


      The regex i use in the prompt is the same as i use in my other scripts which uses Net::Telnet::Cisco. And these works on the XR devices which uses Telnet.


      When i used your prompt i still got the same in the dumps, unfortunately

        So if I understand correctly:

        • Net::Telnet::Cisco - IOS - your prompt - WORKS!
        • Net::SSH2::Cisco- IOS - your prompt - WORKS!
        • Net::Telnet::Cisco - XR - your prompt - WORKS!
        • Net::SSH2::Cisco - XR - your prompt - NOT WORKS :-(

        There are some differences in Net::Telnet and Net::SSH2 that underly the Cisco flavor of these modules that I had to work around for the SSH2 case. Have you tried:

        waitfor_clear => 1 # 1 is default, you use 0 binmode => 1 # 0 is default blocking => 1 # 0 is default Win32 only works with 0

        I'd try each of the above with your new() call one at a time systematically eliminating them. From your OP, the dump seems to indicate the prompt is *not* seen on XR (you don't see "DEVICE" in the XR dump, you do in the IOS dump). The other thing to try is just using Net::SSH2 directly to eliminate if any of the bells and whistles I liberally "borrowed" from Net::Telnet / Net::Telnet::Cisco are causing issues with the way Net::SSH2 makes and maintains its connection.