gpt4 book ai didi

Perl Net::Telnet 在大命令输出上超时

转载 作者:行者123 更新时间:2023-12-01 05:24:02 25 4
gpt4 key购买 nike

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

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 秒。

关于Perl Net::Telnet 在大命令输出上超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14899077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com