我正在编写一个使用Net :: Telnet的程序,但是当我尝试在第41行使用$tel-> cmd时,会发生错误.
command timed-out at CoyoteBridge4000.pl line 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";
解决方法
您是否尝试在构造函数中使用超时选项?
从POD:
Net :: Telnet-> new(-timeout => 20);
该值以秒为单位.我怀疑你可能只是让命令超时等待该命令的响应.默认超时为10秒.