Net SSH Expect打印输出

时间:2011-11-27 12:20:45

标签: perl ssh

我的代码如下

use Net::SSH::Expect;

my $ssh = Net::SSH::Expect->new (
            host => "$node_name",
            user => 'admin',
            timeout => 10,
            raw_pty => 1,
            );

$ssh->run_ssh() or die "SSH process couldn't start: $!";

$ssh->waitfor('password: ');

$ssh->send("$password");

$ssh->waitfor('mml> ');

@ls=$ssh->exec("$command");

print @ls;

#BREAK1: At this point remote device ask for "Press Enter to continue..." because output is more than one page..that is why below code

while ($ssh->waitfor('continue')) {
$line=$ssh->send("\n");
print $line;
}

我想打印所有捕获的输出,但是它只打印由@ls=$ssh->exec("$command");捕获的内容,并且不会打印由BREAK1下面的代码捕获的任何内容。

2 个答案:

答案 0 :(得分:0)

当输出很大时,模块的Perldoc会推荐:

 # When running a command that causes a huge output,
 # lets get the output line by line:
 $ssh->send("find /");   # using send() instead of exec()
 my $line;
 # returns the next line, removing it from the input stream:
 while ( defined ($line = $ssh->read_line()) ) {
     print $line . "\n";
 }

另请注意,send()不应该返回任何内容,您应该使用read_line()或read_all()。 Module doc

答案 1 :(得分:0)

添加此$ssh->exec("stty raw -echo");