Hope you have some time to shed light on with my current problem.
I have a log file from a program that runs in linux(Centos) that I want to export per line to MySQL Database.
This is the log file content that I currently have
1385164910|200|GENERAL|QUEUEPAUSE|Local/202@from-queue/n 1385168102|200|GENERAL|QUEUEREMOVE|1000|Local/202@from-queue/n 1385168125|200|GENERAL|QUEUEUNPAUSE|Local/201@from-queue/n 1385168244|200|GENERAL|QUEUEADD|1000|Local/200@from-queue/n 1385168249|200|GENERAL|QUEUEREMOVE|1000|Local/200@from-queue/n 1385168275|200|GENERAL|QUEUEADD|1000|Local/200@from-queue/n
Now I want each lines to be exported in MySQL, I already know how to create a Perl that works with MySQL and I already know to create a loop to read the logs and it looks like this
#!usr/bin/perl
use strict;
use warnings;
my $file = '/var/log/fop2_audit.log';
open my $info, $file or die "Could not open $file: $!";
my $count = 0;
while( my $line = <$info>) {
use DBI;
$dbh = DBI->connect('dbi:mysql:dbname','username','password')
or die "Connection Error: $DBI::errstr\n";
$sql = "INSERT INTO `Logs`(`logs`) VALUES ($line)";
$sth = $dbh->prepare($sql);
$sth->execute
or die "SQL Error: $DBI::errstr\n";
}
close $info;
but my problem is that how I can remove a line of log text after it's inserted to MySQL. And how can I break down the logs by "|" and insert the breakdown string to MySQL fields.
Ex.
Log: 1385168249|200|GENERAL|QUEUEREMOVE|1000|Local/200@from-queue/n
MySQL: TimeStamp: 1385168249 EXT: 200 Type: GENERAL Action: QUEUEREMOVE Queue: 1000 OtherInfo: Local/200@from-queue/n
Or I can better do this in Python?
Thank you in advance for any help....