我被困在perl脚本上。它应该返回至少5000行,看起来像这样(标题只是fyi):
Interface ----- CMTS Measurements ----- --------- CM Measurements ---------
(DS-US) USPwr USSNR uReflec Timing USPwr DSPwr DSSNR uReflec Timing Last
S/C/CH-S/CG/CH (dBmV) (db) (dBc) Offset (dBmV) (dBmV) (db) (dBc) Offset Polled MAC address
----------------- ------- ------ ------- ------ ------ ------ ------ ------- ------- ------ --------------
12/0/8-1/0/0 -0.4 28.3 0 312832 47.0 -2.4 37.2 24 1222.00 00:23 0000.cfbe.9151 (Arris)
12/0/15-1/0/0 0.0 29.8 0 353280 44.0 -14.4 32.4 30 1380.00 00:22 0017.9635.19b4 (Arris)
12/0/12-1/0/0 0.4 30.3 0 353024 48.0 -4.5 34.9 30 1380.00 00:22 0017.9795.5d3c (Arris)
12/0/15-1/0/0 -0.6 28.7 0 357120 44.0 0.2 38.0 30 1396.00 00:20 0017.a6uz.c781 (Arris)
12/0/14-1/0/0 0.0 28.5 0 354048 45.0 0.2 37.4 25 1383.00 00:20 0017.a289.96ef (Arris)
但不知何故,脚本停在第1500行...... 脚本看起来像这样:
#!/usr/bin/perl -w
use warnings;
use strict;
use Net::SSH2;
my $cmtsip="x.x.x.x";
my $password='somepassword';
my $username="someuser";
# login to cmts and get the table
my $ssh2=Net::SSH2->new();
$ssh2->connect($cmtsip) or die "Unable to connect Host $@ \n";
$ssh2->auth_password($username,$password) or die "Unable to login $@ \n";
my $chan = $ssh2->channel();
$chan->blocking(0);
$chan->shell();
print $chan "show cable modem phy\n";
sleep (40);
while (<$chan>)
{
print $_;
}
$chan->close;
任何人都可以告诉我我的剧本在哪个部分失败了吗?
答案 0 :(得分:0)
我用你的脚本进行了测试。它停止了更快速的
这里略微修改了脚本版本,在我的环境中运行良好:
#!/usr/bin/perl -w
use warnings;
use strict;
use Net::SSH2;
my $cmtsip = "x.x.x.x";
my $password = 'somepassword';
my $username = "someuser";
# login to cmts and get the table
my $ssh2 = Net::SSH2->new();
$ssh2->connect($cmtsip) or die "Unable to connect Host $@ \n";
$ssh2->auth_password($username, $password) or die "Unable to login $@ \n";
my $chan = $ssh2->channel();
$chan->blocking(0);
$chan->shell();
print $chan "show cable modem phy\n";
read_chanel();
sub read_chanel {
while (<$chan>) {
if ($_ =~ /(?m:^\s*--More--)/) {
print $chan " ";
return read_chanel();
}
print $_;
} ## end while (<$chan>)
} ## end sub read_chanel
$chan->close;
除了您的问题,如果您是通过SSH处理Cisco IOS,请查看Net::SSH2::Cisco或Net::Appliance::Session