Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Net::SSH2 just hangs up without any output

by Anonymous Monk
on Aug 28, 2007 at 07:43 UTC ( #635521=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks,

I am new to perl programming i am trying to implementing a small code using Net::SSH2. I am trying to connect to one of my local machine & retrive the hostname of that machine using Net::SSH2 module, whenever i try executing the program then i just get hanged-up without any ouput.

use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2->debug(1); $ssh2->connect('machine') or die " Cannot connect to 219 "; $ssh2->auth_password('username','password') or die " username/password + is wrong "; print "Username/Password is correct\n"; my $chan2 = $ssh2->channel(); $chan2->shell(); print $chan2 "hostname -a\n"; print "LINE : $_" while <$chan2>; $chan2->close;

I want to know whether I am missing any points in implementing the logic.

Thanks in advance
pradeep

Replies are listed 'Best First'.
Re: Net::SSH2 just hangs up without any output
by syphilis (Bishop) on Aug 28, 2007 at 10:46 UTC
    Do you know where it's hanging ? (You could insert some print "Got to here\n"; lines to determine where it's hanging.) If it's hanging after $chan2->shell(); try inserting $chan2->blocking(0);.

    I ran your script on a linux box (localhost) and here's the output:
    Username/Password is correct libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type +, window_size, packet_size, ((void *)0) , 0 ) -> 0x82cf7c0 Net::SSH2::poll: timeout = 250, array[1] - [0] = channel - [0] events 1 - libssh2_poll returned 1 - [0] revents 1 Net::SSH2::Channel::read(size = 1, ext = 0) - read 1 bytes - read 1 total LINE : 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 0x8131de0
    It didn't hang for me ... but then I suspect that's not the output you were looking for.

    Update:With debugging turned off the output reduces to:
    Username/Password is correct LINE :
    (On the same machine, 'hostname -a' returns nothing ... so the output looks about right to me.)

    It would be a good idea to run the Net::SSH2 test suite against the server. (If you've already done that, did all tests pass ?)

    Cheers,
    Rob

      Hi Rob,

      Thanks a lot Rob you were exactly right the problem was with $chan2->blocking(0); being not set. Now i get my outputs right.

      Thankyou,
      pradeep

Re: Net::SSH2 just hangs up without any output
by zentara (Archbishop) on Aug 28, 2007 at 12:45 UTC
Re: Net::SSH2 just hangs up without any output
by Anonymous Monk on Aug 28, 2007 at 10:16 UTC

    The output i get while running i debug mode is:

    Connected to host 192.168.1.217 Username/Password is correct libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type +, window_size, packet_size, ((void *)0) , 0 ) -> 0x8d4d258 Net::SSH2::poll: timeout = 250, array[1] - [0] = channel - [0] events 1

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://635521]
Approved by randyk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2019-12-13 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?