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

I am trying to interact with Nexus device through Windows via Perl script. These device accept SSH only hence I used Net::SSH2 module.

By using this script it throws nothing for cisco device running IOS-XR or NX-OS but works well for Normal IOS device. .>/p>

PPM Call use warnings; use strict; use Term::ANSIColor qw(:constants); use Term::ANSIColor; use Win32::Console::ANSI; #use Text::CSV; use Net::SSH2; Credential declaration / dynamic directory my $user='xxxx'; ### Use your username chomp $user; my $pass='yyyy'; ### Use your Password chomp $pass; my @current_dir=`cd`; $current_dir[0]=~s/\\/\\\\/g; chomp $current_dir[0]; my $ssh = Net::SSH2->new(); #$ssh->debug(1); if(!$ssh->connect('172.16.23.158')){ print BOLD RED "Failed login\n",RESET; } if(!$ssh->auth_password($user,$pass)){ print "Login NOK\n"; } my $channel = $ssh->channel(); $channel->blocking(0); $channel->shell(); print $channel "term len 0\n"; my @junk; push (@junk,"$_") while <$channel>; foreach (@junk) { print BOLD CYAN "$_\n",RESET; }
After doing debug it prints below lines but I do not know what is this.
libssh2_channel_open_ex(ss->session, pv_channel_typ Net::SSH2::poll: timeout = 250, array[1] - [0] = channel - [0] events 1 - libssh2_poll returned 0 - [0] revents 0 Net::SSH2::poll: timeout = 250, array[1] - [0] = channel - [0] events 1 - libssh2_poll returned 0 - [0] revents 0 Net::SSH2::Channel::DESTROY Net::SSH2::DESTROY object 0x3604f98"
Can anyone help to move forward?

Replies are listed 'Best First'.
Re: Perl Net::SSH2 on Window
by dasgar (Priest) on Jan 03, 2016 at 22:17 UTC

    Try taking look at using Control::CLI, which uses Net::SSH2 for SSH connections. With Control::CLI, you can specify logs that can be used to help debug what is going on with your attempt to connect and issue commands.

Re: Perl Net::SSH2 on Window
by salva (Canon) on Jan 04, 2016 at 08:00 UTC
    Don't set non-blocking mode.

    Instead, read lines until you get the shell prompt back. For instance:

    my $channel = $ssh->channel(); $channel->shell(); print $channel "term len 0\n"; while (<$channel>) { last if /^>$/; push @junk, $_; }