Unifix knowledge database - The original one

Dashboard - News - Search - List - About - Admin


Apache (2.x) logfiler i MySQL

Author:mike - Tue May 18 12:36:28 2004

Flg, får apache til at formattere logen og parse den til stdin på mysqllog.pl

CustomLog "| /usr/bin/mysqllog.pl" mysql
LogFormat "%h#%v#%U#%{User-agent}i#%{Referer}i#%s#%b#%r" mysql


Mysqllog parser så input til mysql:
#!/usr/bin/perl
# script: mysqllog
use DBI;
use constant DSN => 'dbi:mysql:system';
use constant DB_TABLE => 'access_log';
use constant DB_USER => 'root';
use constant DB_PASSWD => '--';

$db = DBI->connect(DSN,DB_USER,DB_PASSWD) || die DBI->errstr;
$sth = $db->prepare("INSERT INTO weblog (`remotehost`,`virtualhost`,`path`,`agent`,`referer`,`status`,`size`,`request`,`time`)
 VALUES(?,?,?,?,?,?,?,?,?)")
|| die $db->errstr;

while (<>) {
chomp;
@dat=split("#");
$sth->execute(@dat[0],@dat[1],@dat[2],@dat[3],@dat[4],@dat[5],@dat[6],@dat[7],time());
}
$sth->finish;
$db->disconnect;
Copyright(c) Unifix.org 2002-2011


Dashboard - News - Search - List - About - Admin
 
Powered by Mikjaer Consulting Solutions - Hosted by Specialhosting.dk