Solved

Combine two PERL scripts

Posted on 2008-10-14
4
357 Views
Last Modified: 2008-10-14
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


0
Comment
Question by:ashvillerob
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 250 total points
ID: 22712347

#!/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
 
LVL 1

Author Comment

by:ashvillerob
ID: 22712408
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
 
LVL 39

Expert Comment

by:Adam314
ID: 22712546
I'm assuming you got it working because you accepted an answer.  Is it working?
0
 
LVL 1

Author Comment

by:ashvillerob
ID: 22713176
Yes, It was my error, thansk!
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PERL get the value for query 4 151
PERL export multiple query results to a JSON file 1 165
syslog unix file 20 73
perl syntax 3 4
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question