Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl Net::SSH2输出限制?_Perl_Libssh2 - Fatal编程技术网

Perl Net::SSH2输出限制?

Perl Net::SSH2输出限制?,perl,libssh2,Perl,Libssh2,我被perl脚本绊住了。它应该至少返回5000行,如下所示(仅供参考): 但不知怎的,脚本停在了第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=Ne

我被perl脚本绊住了。它应该至少返回5000行,如下所示(仅供参考):

但不知怎的,脚本停在了第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;
#/usr/bin/perl-w
使用警告;
严格使用;
使用Net::SSH2;
我的$cmtsip=“x.x.x.x”;
我的$password='somepassword';
我的$username=“someuser”;
#登录到cmts并获取表
我的$ssh2=Net::ssh2->new();
$ssh2->connect($cmtsip)或die“无法连接主机$@\n”;
$ssh2->auth_password($username,$password)或死“无法登录$@\n”;
my$chan=$ssh2->channel();
$chan->blocking(0);
$chan->shell();
打印$chan“显示电缆调制解调器物理层\n”;
睡眠(40);
而()
{
打印美元;
}
$chan->close;

有人能告诉我脚本在哪一部分失败吗?

我用你的脚本做了一次测试。它更迅速地停了下来

下面是脚本的稍微修改版本,在我的环境中运行良好:

#!/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;
#/usr/bin/perl-w
使用警告;
严格使用;
使用Net::SSH2;
我的$cmtsip=“x.x.x.x”;
我的$password='somepassword';
我的$username=“someuser”;
#登录到cmts并获取表
我的$ssh2=Net::ssh2->new();
$ssh2->connect($cmtsip)或die“无法连接主机$@\n”;
$ssh2->auth_password($username,$password)或死“无法登录$@\n”;
my$chan=$ssh2->channel();
$chan->blocking(0);
$chan->shell();
打印$chan“显示电缆调制解调器物理层\n”;
读《香奈儿》;
香奈儿酒店{
而(){
如果($)/(?m:^\s*--更多--)/){
打印$chan”“;
返回read_chanel();
}
打印美元;
}##结束时()
}##结束子读取#香奈儿
$chan->close;

除了你的问题之外,看看你是否正在通过SSH处理Cisco IOS,因为目前你的脚本在尝试编译时已经失败了。我没有上传整个脚本,因为其他部分不相关。我的cli上已经有了一个输出,但是正如我所说的,只有一部分行而不是全部行。所以不会编译的代码没有帮助。谢谢你的回答。我已将您的代码添加到脚本中,但它不起作用。问题是,它是Arris CMTS,而不是Cisco硬件。如果我通过ssh从服务器(脚本所在的位置)连接到CMT,并执行命令“show cable modem phy”,我将获得所有预期的线路。这就是我考虑变量限制的原因…看看read方法。它允许您设置缓冲区大小,这可能会导致您的问题
#!/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;