【问题标题】:Perl Net::Telnet timing out on large command outputPerl Net::Telnet 在大型命令输出上超时
【发布时间】:2013-01-31 16:28:21
【问题描述】:

我正在编写一个使用Net::Telnet 的程序,但是当我尝试在第41 行使用$tel->cmd 时,出现错误。

CoyoteBridge4000.pl 第 41 行命令超时

命令有效,但输出很大,这就是我认为发生超时的原因。我能做些什么来解决这个问题?由于我尝试更改超时并没有解决问题。

#!/usr/bin/perl
use Net::Telnet ();
$tel = new Net::Telnet();

print "\nFile Name\n\n";
my $name = <>;
chomp $name;

my @equipament;
my $i        = 0;
my $username = "admin";
my $passwd   = "zhone";
my $certo    = 0;
$co = "bridge show vlan 4000";

open(arquivo, "ip.txt");
my $i = 0;
while (<arquivo>) {
  $equipament[$i] = $_;
  chomp $equipament[$i];
  $i++;
}
close(arquivo);

open(resp, ">$name.csv");
foreach (@equipament) {
  eval { $tel->open($_); };
  if ($@) {
    chomp $_;
    print resp "$_, UNREACHABLE\n";
  }
  else {
    open(re, ">temp.txt");
    $tel->login($username, $passwd);
    ###ERROR###
    @lines = $tel->cmd(String => "$co", Timeout => 600);
    #####ERROR#####
    print re @lines;
    close(re);
    open(re, "temp.txt");
    $encontrar = ":";
    while (<re>) {
      if ($_ =~ /$encontrar/) {
        chomp $_;
        print resp $_;
      }
    }
    close(re);
  }
}
close(resp);

print "\n\n DONE \n\n";

【问题讨论】:

  • 程序是否在超时前等待十分钟?
  • 问题解决了,是设备问题

标签: perl telnet perl-module


【解决方案1】:

您是否尝试过在构造函数中使用超时选项?

从 POD:

Net::Telnet-&gt;new(-timeout =&gt; 20);

该值以秒为单位。我怀疑您可能只是让命令超时等待该命令的响应。默认超时为 10 秒。

【讨论】:

    猜你喜欢
    • 2012-08-16
    • 2017-02-26
    • 2021-02-15
    • 2014-08-29
    • 2020-12-24
    • 2017-02-26
    • 2013-04-09
    • 2015-02-22
    • 2022-01-08
    相关资源
    最近更新 更多