|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Net::SSH2::Channel->exec, grabbing stdoutI'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 ActivePerl@... To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs |
|
|
Re: Net::SSH2::Channel->exec, grabbing stdoutlistmail wrote:
> 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? > my $chan = $ssh2->channel(); > $chan->blocking(0); > > my $returnval = $chan->exec('who') or die "Couldn't exec 'who'\n"; Try several other commands besides who - like 'ls -lF' for eg. Or try 'who --help' and see if that generates usage text. Also try dropping the non-blocking. _______________________________________________ ActivePerl mailing list ActivePerl@... To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs |
|
|
Re: Net::SSH2::Channel->exec, grabbing stdout$Bill :)
Are you using the http://theoryx5.uwinnipeg.ca/ppms/ repo, Net::SSH2 0.09 version? I'm guessing the libssh2 dependency is satisfied in perhaps the SSH2.dll? At least I hope things get installed correctly via ppm. Anyway, I've tried several valid commands such as '/bin/df -k', 'ls', and your suggestions with no success on retrieving output. I've also tried the suggestions at http://www.perlmonks.org/?node_id=621761 which lean towards using shell() with no luck. Bill Luebkert wrote: > listmail wrote: >> 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? > > >> my $chan = $ssh2->channel(); >> $chan->blocking(0); >> >> my $returnval = $chan->exec('who') or die "Couldn't exec >> 'who'\n"; > > Try several other commands besides who - like 'ls -lF' for eg. > Or try 'who --help' and see if that generates usage text. > Also try dropping the non-blocking. _______________________________________________ ActivePerl mailing list ActivePerl@... To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs |
| Free Forum Powered by Nabble | Forum Help |