David Robins wrote:
> On Saturday February 10, 2007 09:30, Serge Leschinsky wrote:
>> I'm trying to see the result of executing "uname -a" on my host.
>> Unfortunately, there is no output from the script. Could you please point
>> me what I do wrong?
>
> Both your test1 and test2 scripts below works fine for me (using Gentoo
> Linux, perl 5.8.8, Net::SSH2 0.09). Try adding a sleep(5) before you start
> reading the output, to see if it's just an output delay.
>
Thank you for the replay. I've tried, but got the same result...
But I did another test and, really, it can be clue.
What I do:
1. execute script with _long_ command
2. measure time of executing for script - really the time depends on sleep(5);
3. check if the process exists.
It looks like the $chan->exec() detach control terminal. It's very useful
behavior but how can I manage it (I mean how to define detach or keep stdin,
stdout etc)?
May I ask you to help me in this? Probably I just missed something important in
the manual for Net::SSH2.
[root@lx-sles ~]# cat 123
#!/usr/bin/perl -w
use strict;
use Net::SSH2;
my $ssh2 = Net::SSH2->new();
print "connect fail\n" unless ($ssh2->connect('127.0.0.1'));
print "password fail\n" unless ($ssh2->auth_password('root', 'xxxx'));
# test2
my $chan=$ssh2->channel();
$chan->exec('LIMIT=10 ; for ((a=1; a <= LIMIT ; a++)) ; do expr 2 \* $a ; sleep
10; done') or warn $!;
sleep(5);
while (<$chan>){ print $_ } ;
$chan->close;
exit 0
[root@lx-sles ~]# time ./123
real 0m5.245s
user 0m0.104s
sys 0m0.008s
[root@lx-sles ~]# ps axf
.......
12273 ? Ss 0:00 bash -c LIMIT=10 ; for ((a=1; a <= LIMIT ; a++)) ; do expr 2 \*
12293 ? S 0:00 \_ sleep 10
--
Sincerely
Serge Leschinsky
|