2017-06-22 23 views
2

私はperlスクリプトにくっついています。それは私にこの(ヘッダだけFYI)のように見える少なくとも5000行を返す必要があります。Perl Net :: SSH2出力制限?

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 [email protected] \n"; 
$ssh2->auth_password($username,$password) or die "Unable to login [email protected] \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

現在、あなたのスクリプトはコンパイル中に既に失敗しています。 – dgw

+0

他の部分は関係ないので、スクリプト全体をアップロードしませんでした。私はすでに私のcliに出力を持っていますが、私はすべての代わりにラインの一部だけがあると言っています。 –

+0

問題を表示するには、[最小限の、完全で検証可能な例](https://stackoverflow.com/help/mcve)を提供する必要があります。だから、コンパイルされないコードは役に立たない。 – dgw

答えて

0

私はあなたのスクリプトでテストを行いました。あなたはSSH経由でシスコを扱っている場合は、Net::SSH2::CiscoまたはNet::Appliance::Sessionを見てみましょうあなたの質問のほかに

#!/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 [email protected] \n"; 
$ssh2->auth_password($username, $password) or die "Unable to login [email protected] \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; 

:それは少し私の環境では正常に動作するスクリプトのバージョンを変更ここでは、より迅速

に停止しましたIOS

+0

あなたの答えをありがとう。スクリプトにコードを追加しましたが、動作しませんでした。問題はArris CMTSでシスコのハードウェアではないことです。サーバー(スクリプトがある場所)からCMTSに向かってsshで接続し、 "show cable modem phy"コマンドを実行すると、私は期待したすべての行を得ます。それは私が変数の制限について考えた理由です... –

+0

[Net :: SSH2 :: Channel](https://metacpan.org/pod/Net::SSH2::Channel#read)のreadメソッドを見てください。バッファサイズを設定できるため、問題が発生する可能性があります – palik