Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Net::SSH2::Cisco and Nexus switches

by cnoyes72 (Initiate)
on Aug 14, 2018 at 17:44 UTC ( [id://1220339]=perlquestion: print w/replies, xml ) Need Help??

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

I'm trying to use the Net::SSH2::Cisco module against Cisco Nexus switches and keep getting a timeout when executing the command. The logs show the command executed (I recieved the expected response from the switch), but the script timesout. This same script runs perfectly against and IOS switch. I think it may be waiting for the prompt but doesn't recognize it. Has anyone had luck getting this to work with Nexus gear?

#!/usr/local/bin/perl # # use strict; use warnings; use Net::SSH2::Cisco; my $t = Net::SSH2::Cisco->new( host => 'nexus-switch', Dump_log => '/root/dump.log', Output_log => '/root/output.log', Input_log => '/root/input.log', Waitfor_clear => '0' ); $t->login( Name => 'name', Password => 'passwd' ); # Execute Command my @output = $t->cmd(string => "show clock"); print @output; $t->close;

Replies are listed 'Best First'.
Re: Net::SSH2::Cisco and Nexus switches
by VinsWorldcom (Prior) on Aug 14, 2018 at 20:47 UTC

    I wrote Net::SSH2::Cisco but never had Nexus switches to test on. It could be a lot of things, including the prompt string. From the CRAPPS utility I wrote:

    ... has an issue with prompt discovery on new Cisco IOS-XR routers. These routers have a prompt like: RP/0/RP1/CPU0:routername# The current Net::Telnet::Cisco prompt matching will not catch this and cause timeouts on Telnet connects to these types of routers. This script sends a new prompt that should match existing prompts and the new IOS-XR prompts. If you are having failed connect issues when in Telnet mode, but logging shows that you are connecting, the custom prompt is the first place to look. Net::Telnet::Cisco supplied prompt: '/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\)) +?\s*$)/' Updated by this program: (?:[\w.\/]+\:)? inserted after the "'/(?m:^" The rest of the line is left as is.

    Note that I wrote Net::SSH2::Cisco as a drop in replacement for Net::Telnet::Cisco, so the same above should apply.

    my $t = Net::SSH2::Cisco->new( [...] prompt => '/(?m:^ [...] s*$)/'; # or whatever matches your prompt );

    Also agree with zentara; waitfor_clear shouldn't need to be messed with, but if you're going to, at least us integer 0 (not '0' string).

      Thanks for the response. It looks like the nexus prompt adds a space after the "#" character. However, now the script appears to be prepending a "Z" before the command. I haven't changed anything in the script beside the prompt match, this makes no sense.

        In waitfor(), if there is a timeout and waitfor_clear() is set, an ios_break('Z') (ctrl-z) is sent. That explains the Z. If you're confident you have the prompt correct, try experimenting with waitfor_clear().

Re: Net::SSH2::Cisco and Nexus switches
by zentara (Archbishop) on Aug 14, 2018 at 19:31 UTC
    Hi, just a WAG (Wild Ass Guess) here, but your
    Waitfor_clear => '0'
    looks suspicious. You are setting it to a string text zero, not a numeric 0. Try it without the ' ' marks. Also try setting it to 1, which is the default. There is some discussion about this in the perldoc for the module at Net::SSH2::Cisco

    I'm not really a human, but I play one on earth. ..... an animated JAPH
Re: Net::SSH2::Cisco and Nexus switches
by Larry-W (Initiate) on Oct 18, 2018 at 11:02 UTC
    Did you figure this out?
    Im struggling with the same issue, my prompt is working with IOS and IOS XR.
    /(?m:^(?:[\w.\/]+\:)?(?:[\\w.-]+\@)?[\\w.-]+\\s?(?:\(config[^\)]*\))?\\s?(?:\(admin-config[^\)]*\))?\\s?[\$#>]\s?(?:\(enable\))?\\s*$)/
    With $session->errmsg; i see that is timing out on $session->cmd('show clock'); on NXOS. on IOS and IOS XR it prints the output of the array. This is dump from Nexus switch
    > 0x00000: 73 68 6f 77 20 63 6c 6f 63 6b 0a show cl +ock. < 0x00000: 31 32 3a 35 32 3a 30 33 2e 37 30 32 20 53 56 47 12:52:0 +3.702 SVG < 0x00010: 20 54 68 75 20 4f 63 74 20 31 38 20 32 30 31 38 Thu Oc +t 18 2018 < 0x00020: 0a .
    This is dump from IOS switch
    < 0x00000: 0d 0a 49 4f 53 53 57 49 54 43 48 23 ..IOSSW +ITCH# > 0x00000: 73 68 6f 77 20 63 6c 6f 63 6b 0a show cl +ock. < 0x00000: 73 68 6f 77 20 63 6c 6f 63 6b 0d 0a show cl +ock.. < 0x00000: 31 32 3a 35 34 3a 35 30 2e 35 30 30 20 53 56 47 12:54:5 +0.500 SVG < 0x00010: 20 54 68 75 20 4f 63 74 20 31 38 20 32 30 31 38 Thu Oc +t 18 2018 < 0x00020: 0d 0a 49 4f 53 53 57 49 54 43 48 23 ..IOSSW +ITCH#
      After long time i fail in same problem
      using strawberry and Net:SSH2::Cisco to access ios is ok but i fail with nexus 7.0(3)I4(3) (a bit old) box.

      i see i receive all from the swicth but at the end of "show version" after crlf i receive some char in the SSH channel and before the promt i got a CR again and prompt is not recognized, so i got a timeout.

      i try to play with the params with no luck.

      Anyone use it with nexus ?

      thanks in advance

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1220339]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-29 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found