[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Send PERL output to MySQL

Asked by ashvillerob in Perl Programming Language

Tags: perl, output, column, mysql

I have the following script that logs into a Cisco Router and runs a command and returns the output to a file. I need this modified to send the output to a MySQL database using DBI. I know almost no PERL, so pleae edit this script rather than offering suggestions thanks!

#!/usr/bin/perl

#    Use the script as follows script.pl ipaddress > output_file_name
#
use Net::Telnet;
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->login('username','password');
$t->cmd("terminal length 0");
print $ip;
print "\n\n@lines\n";
my @lines = $t->cmd("scm phy");
print "\n\n@lines\n";
$t->cmd("");
$t->close;
}

Sample output below(please note that the first two lines returned can be stripped off. I only want the raw data which is 10 columns. From left to right the columns would be (mac,int,sid,uspwr,ussnr,timing,micro,dspwr,dssnr,mode)


<router ip>

MAC Address    I/F         Sid  USPwr  USSNR  Timing MicroReflec DSPwr  DSSNR  Mode
                                 (dBmV) (dBmV) Offset (dBc)       (dBmV) (dBmV)    
 0016.9242.d556 C3/0/U1     81  38.00   26.78   2033  33           1.01  37.06  tdma
 0002.8ace.3348 C3/0/U4     82  45.03   26.14   4697  35          -14.01  33.00  tdma
 0002.8ac5.cd22 C3/0/U3     85  37.08   27.80   3987  37          12.07  35.04  tdma
 0002.8ac7.60cc C3/0/U4     86  35.00   27.12   4634  38           2.02  33.06  tdma
 0002.8ac7.61d4 C3/0/U5     87  61.00   22.72   4896  36          -5.08  34.08  tdma
[+][-]04/03/07 09:29 PM, ID: 18848481Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/04/07 12:31 AM, ID: 18848927Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/04/07 07:20 AM, ID: 18850754Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/04/07 08:05 AM, ID: 18851087Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/04/07 09:27 AM, ID: 18851784Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/04/07 10:06 AM, ID: 18852033Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89