Combine two PERL scripts

I use one script to pull data from a Cisco router then the second scripts uses the output file of the frist script to output the final file.

I wish to combine these into a single script.

FIRST SCRIPT:
#!/usr/bin/perl

#    Use the script as follows C:> PERL script.pl ipaddress > output_file_name
#
use Net::Telnet;
my $MB = 1024 * 1024;
open (FILE,@ARGV[0])|| die "Sorry, I can't seem to find @ARGV[1]. Please check
$my @lines;
the spelling.\n";
print "\n";
while (<FILE>) {
my $ip = $_;

my $t = Net::Telnet->new(Timeout => 240,
                    Prompt => '/.*#/',
                          Host => $ip);
my $debug=$ARGV[1];
$t->max_buffer_length(5 * $MB);
$t->login('username','password');
$t->cmd("terminal length 0");
print $ip;
my @lines = $t->cmd("show cable modem docsis device-class | in MTA");
print "\n\n@lines\n";
$t->cmd("");
$t->close;
}

SECOND SCRIPT
perl -ane "print \"clear cable modem $F[0] reset\n\"" mtas > newfile.txt

BTW....running this on Windows


LVL 1
ashvillerobAsked:
Who is Participating?
 
Adam314Connect With a Mentor Commented:

#!/usr/bin/perl
# Use the script as follows C:> PERL script.pl ipaddress > output_file_name
#
use Net::Telnet;
 
my $FileName = shift;
die "Usage: $0 <ipaddress_file>\n" unless $FileName;
my $debug = shift;
 
my $MB = 1024 * 1024;
open (my $File, $FileName) or die "Could not open $FileName: $!\n";
print "\n";
while (<$File>) {
    my $t = Net::Telnet->new(
        Timeout => 240,
        Prompt => '/.*#/',
        Host => $_);
    $t->max_buffer_length(5 * $MB);
    $t->login('username','password');
    $t->cmd("terminal length 0");
    print $_;
    my @lines = $t->cmd("show cable modem docsis device-class | in MTA");
    foreach my $line (@lines) {
        print "clear cable modem " . (split(/\s+/,$line))[0] . " reset\n";
    }
    $t->cmd("");
    $t->close;
}

Open in new window

0
 
ashvillerobAuthor Commented:
I get the following error:

Can't locate object method "Select" via package "All" (perhaps you forgot to load "All"?) at script.pl line 29, <$File> line
21.

0
 
Adam314Commented:
I'm assuming you got it working because you accepted an answer.  Is it working?
0
 
ashvillerobAuthor Commented:
Yes, It was my error, thansk!
0
All Courses

From novice to tech pro — start learning today.