【发布时间】:2015-05-12 00:33:03
【问题描述】:
我制作了连接到我的交换机的脚本,但问题是当查看它时只显示部分内容,其余部分显示为大小(--更多)。如何查看所有配置,谢谢
use Net::OpenSSH;
use warnings;
use Expect;
my $password = 'admin';
my $enable = '';
my $ip = '192.16.25.39';
my $username='user';
my $ssh = Net::OpenSSH->new("$username:$password\@$ip", timeout => 200) ;
$ssh->error and die "unable to connect to remote host: ". $ssh->error;
my $output = $ssh->capture({stdin_data => "enable\n"."admin%\n"."show vlan"."\n"});
if ($output) {print $output . ' ';}
my $line;
print "\n";
# closes the ssh connection
$ssh->close();
我已经用 Expect 模块尝试过这个:
use Net::OpenSSH;
if ($output) {
print $output . ' ';
my $expect = Expect->init($output);
$expect->raw_pty(1);
#$expect->debug(2);
my $debug and $expect->log_stdout(1);
while(<$pty>) {
print "$. $_ "
}
}
产生此错误:
无法在 /usr/local/share/perl5/Expect.pm 第 202 行 (#1) (F) 祝福非引用值。这就是 Perl 如何“强制”封装对象。参见 perlobj。用户代码中未捕获的异常:Can't bless non-reference value at /usr/local/share/perl5/Expect.pm line 202. at /usr/local/share/perl5/Expect.pm line 202. Expect::exp_init ("期待", "\x{d}\x{a}witch>enable\x{d}\x{a}密码:\x{d}\x{a}switch#show vlan\x{d} \x{a}\x{d}\x{a}VLA"...) 在 b.pl 第 19 行调用"
【问题讨论】:
-
“--More--”输出听起来像是交换机本身响应“show vlan”命令而产生的。我想看看您是否可以发出命令,使开关在返回之前不等待键盘输入。如果无法做到这一点,使用Expect module with Net::OpenSSH 可能会有所帮助。
-
我用过Expect,但是遇到了问题:(
-
当我使用 Expect 时,我有这样的消息,例如输出“can't bless non-reference value at /usr/local/share/perl5/expect .pl line 202”任何解决方案好吗?跨度>
-
我用expect试试这个:使用Net::OpenSSH;如果($输出){打印$输出。 ' ';我的 $expect = Expect->init($output); $expect->raw_pty(1); #$expect->debug(2);我的 $debug 和 $expect->log_stdout(1); while() { print "$.$_" }}
-
这就是问题“不能在 /usr/local/share/perl5/Expect.pm 第 202 行 (#1) (F) 祝福非引用值。这就是 Perl “强制”封装对象的方式。参见 perlobj。用户代码中未捕获的异常:Can't bless non-reference value at /usr/local/share/perl5/Expect.pm line 202. at /usr/local/ share/perl5/Expect.pm 第 202 行。Expect::exp_init("Expect", "\x{d}\x{a}witch>enable\x{d}\x{a}password:\x{d} \x{a}switch#show vlan\x{d}\x{a}\x{d}\x{a}VLA"...) 在 b.pl 第 19 行调用"