2

I'm stucked on a perl script. It should return me at least 5000 lines that look like this (header just 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)    

But somehow the script stops at line 1500... The Script looks like this:

#!/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;

Can anyone please tell me at which part my script fails?

n. traber
  • 29
  • 2
  • As it currently is your script fails already while trying to compile. – dgw Jun 22 '17 at 17:48
  • I didn't upload the whole script, because the other parts are not relevant. I already have a output on my cli but as i said there's only a part of the lines instead of all of them. – n. traber Jun 22 '17 at 18:03
  • Well, to show the problem you should provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). So code that won't compile is no help. – dgw Jun 22 '17 at 19:21

1 Answers1

0

I did a test run with your script. It stopped on more prompt

Here slightly modified version of the script, which works fine in my environment:

#!/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;

Beside your question, take a look at Net::SSH2::Cisco or Net::Appliance::Session if you are via SSH dealing with Cisco IOS

palik
  • 2,425
  • 23
  • 31
  • Thanks for your answer. I've added your Code to my script but it did not work. The problem is, it's an Arris CMTS and not Cisco hardware. If I connect over ssh from the server (where the script is) towards the CMTS and execute the command "show cable modem phy" I get all the lines I expected. That's the reason I thought about a variable limitation... – n. traber Jun 27 '17 at 10:22
  • take a look at [Net::SSH2::Channel](https://metacpan.org/pod/Net::SSH2::Channel#read) read method. It allow you to set buffer size, which could cause your issue – palik Jun 27 '17 at 12:13