【问题标题】:perl telnet - how to handle multiple pages of outputperl telnet - 如何处理多页输出
【发布时间】:2013-02-17 22:55:46
【问题描述】:

我正在编写一个脚本来通过保存输出“show run”来保存交换机配置,因为固件在通过 tftp 工作时存在问题。 “show run”的输出除以帖子More: <space>, Quit: q, One line: <return>

# sh run
no spanning-tree
interface port-channel 1
shutdown
exit
interface port-channel 2
shutdown
exit
interface port-channel 3
shutdown
exit
interface port-channel 4
shutdown
exit
interface port-channel 5
shutdown
exit
interface port-channel 6
shutdown
exit
interface port-channel 7
shutdown
exit
More: <space>,  Quit: q, One line: <return>

下面是我的部分脚本:

foreach (@linksys_sps){
  print ("Connecting to ",$_,"\n");
  my $telnet = new Net::Telnet ( Timeout=>10,Errmode=>'return');
  $telnet->open($_);
  if ($telnet->errmsg){
    print "Can't connect to " . $_ . " Error: " . $telnet->errmsg . "\n";
  } else {
    $telnet->waitfor('/User Name:$/i');
    $telnet->print('admin');
    $telnet->waitfor('/Password:$/i');
    $telnet->print('password');
    my @lines = $telnet->cmd("sh run");
    print @lines;
    sleep(5);
    $telnet->print('exit');
  }
}

以及他的工作成果:

# sh run
no spanning-tree
interface port-channel 1
shutdown
exit
interface port-channel 2
shutdown
exit
interface port-channel 3
shutdown
exit
interface port-channel 4
shutdown
exit
interface port-channel 5
shutdown
exit
interface port-channel 6
shutdown
exit
interface port-channel 7
shutdown
exit
More: <space>,  Quit: q, One line: <return>

如何解决?

【问题讨论】:

    标签: perl telnet multipage


    【解决方案1】:

    您的交换机上是否有将页面长度设置为零 (0) 的选项?如果是这样,您必须在执行“sh run”命令之前添加它。

    【讨论】:

      【解决方案2】:

      在阿尔卡特 6224 和相同的戴尔 powerconnect 3548 上它可以工作:

      my @lines = $telnet->cmd("terminal datadump");
      @lines = $telnet->cmd("show run");
      

      【讨论】:

        猜你喜欢
        • 2011-06-26
        • 2011-01-15
        • 2021-02-15
        • 1970-01-01
        • 2011-04-06
        • 1970-01-01
        • 2011-07-26
        • 2023-03-09
        • 1970-01-01
        相关资源
        最近更新 更多