Hi,
As per your advice i changed the code to this
----------------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
#use Term::ReadKey;
use Net::SSH2;
my $ssh2 = Net::SSH2->new();
print "connect fail\n" unless ($ssh2->connect('sys5'));
print "password fail\n" unless ($ssh2->auth_keyboard(xyz','mypass')));
my $buf;
my $chan = $ssh2->channel();
$chan->shell();
print $chan "uname -a\n";
select(undef,undef,undef,0.2);
my $out = "";
$out .= $buf while ((my $len = $chan->read($buf, 1000)) > 0);
print $out;
---------------------------------------------------------------------------------------------------
When i run this script, i still don't get any output., am i doing anything
wrong.........can u kindly help me with this..........any links or mailing
lists which can solve this problem would be appreciated
Thanks,
Monnappa
On Thu, Nov 20, 2008 at 3:27 AM, Stewart Rounds <sar...@us...> wrote:
> monnappa appaiah wrote:
> -snip-
>
>> my $chan = $ssh2->channel();
>> $chan->shell();
>> print $chan "uname -a\n";
>> print "LINE: $_" while <$chan>;
>> print $chan "who\n";
>> print "LINE: $_" while <$chan>;
>> $chan->close;
>>
>
> Hi.
>
> The 'print "LINE: $_" while <$chan>;' doesn't work for me either.
> Instead, you need to monitor the channel's read buffer, like:
>
> select(undef,undef,undef,0.2);
> $out = "";
> $out .= $buf while (($len = $chan->read($buf,512)) > 0);
> print $out;
>
> You can find examples of this online in various places. You
> may have to add some sort of timeout or a loop to ensure that
> you read all that is to be read before moving on.
>
> I hope this helps.
>
> -Stewart Rounds
> U.S. Geological Survey
>
|