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?
 
TIA
 
richf
 
#!/usr/local/bin/perl
use warnings;
use strict;
use Net::SSH2;
use Getopt::Std;
 
our($opt_s, $opt_p);
getopts('p:s:');
 
my $passwd = $opt_p ? $opt_p : usage();
my $server = $opt_s ? $opt_s : usage();
 
print "Connecting to $server...\n";
 
my $ssh2 = Net::SSH2->new();
$ssh2->debug(1);
$ssh2->connect($server) or die "Can't connect to $server\n";
 
if( $ssh2->auth_password('root', $passwd)) {
        my $chan = $ssh2->channel();
        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";
}

 
[EMAIL PROTECTED]:/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 = 1024, ext = 0)
- read 44 bytes
- read 0 bytes
- read 44 total
root     tty1         Mar  9 10:55         
Net::SSH2::Channel::read(size = 1024, ext = 0)
- read 0 bytes
- read 0 total
Net::SSH2::Channel::DESTROY
Net::SSH2::DESTROY object 0x867c4c80
[EMAIL PROTECTED]:/home/richf/bin] 
[EMAIL PROTECTED]:/home/richf/bin] 
[EMAIL PROTECTED]:/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 = 1024, ext = 0)
- read 0 bytes
- read 0 total
Net::SSH2::Channel::DESTROY
Net::SSH2::DESTROY object 0x81245b40

Reply via email to