2011-11-27 51 views
1

我的代码如下净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捕获任何东西。当输出大模块的

回答

0

的Perldoc reccomends如下:

# 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"; 
} 

还要注意,发送()是不应该返回任何东西,你应该使用read_line()或read_all()。 Module doc

+0

您好,我试过相同,它可以很好地用于第二页只(基本上我有5-6页输出的)..它打印两页,但没有打印第二页以后的页面....任何帮助? – Mahesh

+0

我认为你可以尝试检查每一行'继续',如果发现模式发送返回饲料在while循环内。另一种方法是在调用waitfor('continue')循环后使用before()函数。 –

+0

天啊!最后它完成了......做{sr-> send(“\ n”); $ line = $ ssh-> read_line(); push(@ls,“$ line”); } while($ line!〜/ mml> /); foreach(@ls){ print“$ _ \ n”; } – Mahesh

0

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

+0

请将您的代码放在'代码块'的'代码(内联)'字符的帮助下。对于代码段,在每行的文本前面添加4个空格。谢谢! – ibiza

+0

提供更多信息,告诉海报为什么你认为这会解决他们的问题或他们做错了什么。 – SashaZd