Perl 显示配置的一部分(--更多)

Perl 显示配置的一部分(--更多),perl,cisco-ios,expect.pm,Perl,Cisco Ios,Expect.pm,我制作了连接到交换机的脚本,但问题是,当查看它时,只显示部分,其余部分显示为大小(--More)。如何查看所有配置并感谢您 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

我制作了连接到交换机的脚本,但问题是,当查看它时,只显示部分,其余部分显示为大小(--More)。如何查看所有配置并感谢您

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 "$. $_ "
    }
}
使用Net::OpenSSH;
如果(产出){
打印$output。“;
my$expect=expect->init($output);
$expect->raw_pty(1);
#$expect->debug(2);
我的$debug和$expect->log\u stdout(1);
while(){
打印“$。$\”
}
}
这将产生以下错误:

无法祝福/usr/local/share/perl5/Expect.pm第202行(#1)(F)的非参考值,只能祝福硬参考。这就是Perl“强制”对象封装的方式。见perlobj。来自用户代码的未捕获异常:无法在/usr/local/share/perl5/Expect.pm第202行中保留非参考值。在/usr/local/share/perl5/Expect.pm第202行。Expect::expu init(“Expect”,“\x{d}\x{a}开关>启用\x{d}\x{a}密码:\x{d}\x{a}开关#显示vlan\x{d}\x{a}\x{d}\x{a}VLA”…)在b.pl第19行调用”


这可能是解决您的问题的更好方法。有一个模块简化了与远程路由器的大量交互。显然,您可以首先使用
Net::OpenSSH
设置加密SSH连接,然后使用该连接的文件句柄启动
Net::Telnet::Cisco
会话

因此,我认为这样做比直接使用
Net::OpenSSH
更有希望:

use Net::OpenSSH;
use Net::Telnet::Cisco;

my $password = 'admin';
my $enable = '';
my $ip = '192.16.25.39';
my $username='user';
my $ssh = Net::OpenSSH->new("$username:$password\@$ip", timeout => 200) ;
my ($pty, $pid) = $ssh->open2pty({stderr_to_stdout => 1})
  or die "unable to start remote shell: " . $ssh->error;
my $cisco = Net::Telnet::Cisco->new(
              -fhopen => $pty,
              -telnetmode => 0,
              -cmd_remove_mode => 1,
              -output_record_separator => "\r");
my @vlan = $cisco->cmd("show vlan");

我不熟悉配置Cisco路由器的细节,因此您必须从这里开始,但在我看来,这是一条更容易获得所需内容的路线。

更--“输出听起来像是交换机本身根据“显示vlan”生成的“命令。我想看看你是否能以这样一种方式发出命令,开关在返回之前不会等待键盘输入。如果不能做到这一点,使用可能会有所帮助。我使用了Expect,但我遇到了问题:(当我使用Expect时,我有这样一条消息,比如输出“不能在/usr/local/share/perl5/Expect.pl第202行祝福非参考值”请回答任何问题?我尝试使用Expect:use Net::OpenSSH;If($output){print$output.'';my$expect=expect->init($output);$expect->raw_pty(1);#$expect->debug(2);my$debug和$expect->log_stdout(1);while(){print“$.$”}}这就是问题“不能在/usr/local/share/perl5/expect.pm第202行(#1)(F)为非引用值祝福”只能祝福硬引用。这就是Perl“执行”的方式“对象的封装。请参阅用户代码中的perlobj.Uncaught异常:不能在/usr/local/share/perl5/Expect.pm行202.at/usr/local/share/perl5/Expect.pm行202.Expect::exp_init(“Expect”,“\x{d}\x{a}witch enable\x{d}\x{a}密码:\x{d}\x{a}a}a}a}在b.pl第19行调用”