4

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

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";
4

1 回答 1

1

Have you tried using the timeout option in your constructor?

From the POD:

Net::Telnet->new(-timeout => 20);

The value is in seconds. I suspect that you might just be having the command time out waiting for a response from that command. The default timeout is 10 seconds.

于 2013-08-23T18:27:38.833 回答