I've just started testing Net::SSH2 in hopes to eventually replace Net::SSH[::W32Perl]. I am having trouble retrieving the stdout data from channel->exec. I do not require an interactive shell, just an ability to execute commands and retrieve the stdout + statuses. Is there something I am missing or do I need to do something different altogether?
: borrowed code from: http://www.nntp.perl.org/group/perl.beginners/2008/04/msg99926.html #!/usr/bin/perl -w use strict; use warnings; use Net::SSH2; #-- my $server='server'; my $user='user'; my $passwd='password'; #-- my $ssh2 = Net::SSH2->new(); $ssh2->debug(1); print "Connecting to $server...\n"; $ssh2->connect($server) or die 'connect problem'; if( $ssh2->auth_password($user, $passwd)) { my $chan = $ssh2->channel(); $chan->blocking(0); my $returnval = $chan->exec('who') or die "Couldn't exec 'who'\n"; my($len, $buff); while($len = $chan->read($buff, 1024)) { print $buff; } $chan->close; } else { print "Invalid username or password $!\n"; } sub usage { die "usage: $0 -s <server> -p <passwd>\n"; } #The following is the output, word for word: Connecting to server... libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type, window_size, packet_size, ((void *)0) , 0 ) -> 0x22e0130 Net::SSH2::Channel::read(size = 1024, ext = 0) - read 0 bytes - read 0 total Net::SSH2::Channel::DESTROY Net::SSH2::DESTROY object 0x206185c _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
