Apr 9, 2008 9:20 pm
Richard Fernandez------_=_NextPart_001_01C89A87.7BA96B7A
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi folks,
=20
I have a test script ( mostly ripped from a posting I found on a CPAN
forum) which uses Net::SSH2 to run a `who' command on a remote server.
The script works fine for most servers, but I have a few boxes where,
despite being able to login, I get no output.=20
Anyone have any ideas why this might be happening?
=20
TIA
=20
richf
=20
#!/usr/local/bin/perl
use warnings;
use strict;
use Net::SSH2;
use Getopt::Std;
=20
our($opt_s, $opt_p);
getopts('p:s:');
=20
my $passwd =3D $opt_p ? $opt_p : usage();
my $server =3D $opt_s ? $opt_s : usage();
=20
print "Connecting to $server...\n";
=20
my $ssh2 =3D Net::SSH2->new();
$ssh2->debug(1);
$ssh2->connect($server) or die "Can't connect to $server\n";
=20
if( $ssh2->auth_password('root', $passwd)) {
my $chan =3D $ssh2->channel();
my $returnval =3D $chan->exec('who') or die "Couldn't exec
'who'\n";
=20
my($len, $buff);
while($len =3D $chan->read($buff, 1024)) {
print $buff;
}
$chan->close;
}
else {
print "Invalid username or password $!\n";
}
=20
=20
sub usage {
die "usage: $0 -s <server> -p <passwd>\n";
}
=20
[richf@richx:/home/richf/bin] ./mytest.pl -s server1 -p passwd
Connecting to server1...
libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type,
window_size, packet_size, 0L , 0 ) -> 0x89bb0600
Net::SSH2::Channel::read(size =3D 1024, ext =3D 0)
- read 44 bytes
- read 0 bytes
- read 44 total
root tty1 Mar 9 10:55 =20
Net::SSH2::Channel::read(size =3D 1024, ext =3D 0)
- read 0 bytes
- read 0 total
Net::SSH2::Channel::DESTROY
Net::SSH2::DESTROY object 0x867c4c80
[richf@richx:/home/richf/bin]=20
[richf@richx:/home/richf/bin]=20
[richf@richx:/home/richf/bin] ./mytest.pl -s server2 -p passwd
Connecting to server2...
libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type,
window_size, packet_size, 0L , 0 ) -> 0x8241e600
Net::SSH2::Channel::read(size =3D 1024, ext =3D 0)
- read 0 bytes
- read 0 total
Net::SSH2::Channel::DESTROY
Net::SSH2::DESTROY object 0x81245b40
------_=_NextPart_001_01C89A87.7BA96B7A--
Apr 9, 2008 9:26 pm
Chas. OwensOn Wed, Apr 9, 2008 at 5:20 PM, RICHARD FERNANDEZ <rfernandez@arrow.com> wrote:
> Hi folks,
>
> I have a test script ( mostly ripped from a posting I found on a CPAN
> forum) which uses Net::SSH2 to run a `who' command on a remote server.
> The script works fine for most servers, but I have a few boxes where,
> despite being able to login, I get no output.
> Anyone have any ideas why this might be happening?
snip>
> I have a test script ( mostly ripped from a posting I found on a CPAN
> forum) which uses Net::SSH2 to run a `who' command on a remote server.
> The script works fine for most servers, but I have a few boxes where,
> despite being able to login, I get no output.
> Anyone have any ideas why this might be happening?
The first step is determining what, if anything, is different about
the machines that you cannot get output from (OS, SSH Server,
environment of the user, etc).
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
wonkden.net
The most important skill a programmer can have is the ability to read.
Apr 10, 2008 1:31 pm
ZentaraOn Wed, 9 Apr 2008 17:20:06 -0400, rfernandez@arrow.com ("RICHARD
FERNANDEZ") wrote:
>Hi folks,
>
>I have a test script ( mostly ripped from a posting I found on a CPAN
>forum) which uses Net::SSH2 to run a `who' command on a remote server.
>The script works fine for most servers, but I have a few boxes where,
>despite being able to login, I get no output.
>Anyone have any ideas why this might be happening?
>
Try setting: >
>I have a test script ( mostly ripped from a posting I found on a CPAN
>forum) which uses Net::SSH2 to run a `who' command on a remote server.
>The script works fine for most servers, but I have a few boxes where,
>despite being able to login, I get no output.
>Anyone have any ideas why this might be happening?
>
$chan->blocking(0);
> my $chan = $ssh2->channel();
zentara
Apr 10, 2008 6:37 pm
Richard Fernandez> -----Original Message-----
> From: Linux@lists.develooper.com
> [mailto:Linux@lists.develooper.com] On Behalf Of zentara
> Sent: Thursday, April 10, 2008 9:31 AM
> To: beginners@perl.org
> Subject: Re: Sometimes Net::SSH2 can't read() from channel?
>
> On Wed, 9 Apr 2008 17:20:06 -0400, rfernandez@arrow.com ("RICHARD
> FERNANDEZ") wrote:
>
>
> $chan->blocking(0);
>
> zentara
>
> From: Linux@lists.develooper.com
> [mailto:Linux@lists.develooper.com] On Behalf Of zentara
> Sent: Thursday, April 10, 2008 9:31 AM
> To: beginners@perl.org
> Subject: Re: Sometimes Net::SSH2 can't read() from channel?
>
> On Wed, 9 Apr 2008 17:20:06 -0400, rfernandez@arrow.com ("RICHARD
> FERNANDEZ") wrote:
>
> >Hi folks,
> >
> >I have a test script ( mostly ripped from a posting I found on a CPAN
> >forum) which uses Net::SSH2 to run a `who' command on a
> remote server.> >
> >I have a test script ( mostly ripped from a posting I found on a CPAN
> >forum) which uses Net::SSH2 to run a `who' command on a
> >The script works fine for most servers, but I have a few
> boxes where, > >despite being able to login, I get no output.
> >Anyone have any ideas why this might be happening?
> >
> Try setting: > >Anyone have any ideas why this might be happening?
> >
>
> $chan->blocking(0);
>
> > my $chan = $ssh2->channel();
> > zentara
>
Thank you, zentara. It seems this is what was needed.
richf
Previous Thread: How to extract digits by position in a string?
Next Thread: Re: how to globalize a lexical variable inside a sub routine
Related Forum Topics
- Sending XML data file to the XML channel
- No output Net::SSH2
- Problem installing Net::SSH2
- Getting error when running Net::SSH2
- Stripped output from Net::SSH2
- Connecting to multiple hosts using Net::SSH2
- Unable to connect to all the hosts using Net::SSH2 module
- How to read from keyboard?
- .profile not being read
- Read and write