вот она, я ее переделал с проги, к-ую нашел в инете, там формат логов был другой и интерфейс с postgre старенький
есть, понятно, еще и вторая часть, к-ая блокировкой занимается, но она отношения к теме не имеет
самую суть я звездочками выделил
#!/usr/bin/perl
use strict;
use DBI;
my ($remotehost,$rfc931,$authuser,$date,$request,$status,$bytes,$resultcode);
my ($sql, $type1, $type2);
my $dbh = DBI->connect("dbi:Pg:dbname=squid;host=localhost","","",
{PrintError => 0});
if ((defined $DBI::err) and ($DBI::err !=0)){
print $DBI::errstr."\n";
exit($DBI::err);
}
# Open squid log file generated by `squid -k rotate`
open (FILE, "/var/log/squid/access.log") or die;
while(<FILE>) {
m/^(\S+)\s(\S+)\s(\S+)\s\[(\S+\s).+?\]\s\"(.+?)\"\s(\d+?)\s(\d+?)\s(\S+)$/;
$remotehost = $1; # address of the remote host
$rfc931 = $2; # remote logname of the user
$authuser = $3; # the username as which the user has authenticated himself
$date = $4; # date and time of the request
$request = $5; # the request line exactly as it came from the client
$status = $6; # the HTTP status code returned to the client
$bytes = $7; # the content-length of the document transferred
$resultcode = $8; # hierarchy code
$request =~ s/ICP_QUERY/GET/;
$request =~ s/\'//g;
($type1,$type2) = split (/:/,$resultcode);
*********************************************************************
if ((($type1 eq 'TCP_MISS') or ($type1 eq 'TCP_REFRESH_MISS')
or ($type1 eq 'TCP_CLIENT_REFRESH_MISS')) and ($request =~ /^GET/)
and ($type2 ne 'NONE') and ($bytes != 0)) {
*********************************************************************
$sql = "INSERT INTO squid VALUES ('$date','$remotehost','$bytes','$request','$rfc931')";
&sqlexec ($sql,$dbh);
}
}
close (FILE);
# delete temporary data in
# ip_clients and auth_clients tables
$sql = "delete from access_auth"; &sqlexec ($sql,$dbh);
$sql = "delete from access_ip"; &sqlexec ($sql,$dbh);
# fill in data of downloaded sizes
$sql = "INSERT INTO access_auth SELECT ident, sum(size) FROM squid WHERE ident <> '-' GROUP BY ident";
&sqlexec ($sql,$dbh);
$sql = "INSERT INTO access_ip SELECT host, sum(size) FROM squid WHERE ident = '-' GROUP BY host";
&sqlexec ($sql,$dbh);
exit;
# -----------------------------------------------------------
sub sqlexec {
my ($sql,$dbh)=@_;
my $sth = $dbh->prepare($sql);
my $rv = $sth->execute();
if(!defined $rv) {
print "Error while $sql\n";
print $dbh->errstr."\n";
exit;
}
}