2013-02-15 145 views
4

我正在编写一个使用Net::Telnet的程序,但是当我尝试在第41行中使用$tel->cmd时,发生错误。Perl Net :: Telnet在超大命令输出时超时

命令超时在CoyoteBridge4000.pl线41

的COMAND是有效的,但产量大,这就是为什么我认为发生超时。我能做些什么来解决这个问题?由于我试图改变超时时间,并没有解决问题。

#!/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 ([email protected]) { 
    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"; 
+0

程序在超时前等待十分钟吗? – Borodin 2013-02-15 21:11:07

+1

问题解决了,这是一个设备问题 – user2076234 2013-02-27 12:28:09

回答

1

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

从POD:

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

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