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','pass
word');
$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,t
iming,micr
o,dspwr,ds
snr,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