[NBLUG/talk] Apache2 + cronolog problems

Rob Orsini orsini at oreilly.com
Mon May 30 05:36:35 PDT 2005


On May 15, 2005, at 3:40 PM, Rob Orsini wrote:

> <vhost...>
> CustomLog "|/www/sbin/cronolog /var/log/www/orsini.us/%Y/bob" combined
> </vhost>

So to follow up: Uhh... there's no /www/sbin on my system (or 
anybody's) and so down came my CustomLog pipe to Cronolog--killed by 
typo. Doh! And the final directory convention I ended up going with for 
all my sites is /var/log/www/each-site/%Y/%m/access.%m-%d-%Y.log.

Right, so the whole point of getting my log files all squared away and 
organized was to be able to run AWstats in an automated manner 
(http://www.awstats.org/). I ran into another little hitch in my 
journey towards site statistics nirvana: So the AWstats cycle is one of 
cooking up a database full of stats for each site and then burning html 
based on that db for your viewing pleasure. You configure AWstats for 
each site that you want to process the logs of with a file like 
/etc/awstats/awstats.www.each-site.com.conf. There's a slew of options 
in that file but the key here is the LogFile option. You can hard-code 
the specific log file you want to process each day but there had better 
be another way. Enter: My next problem.

So the docs say that any option in the config file may be overridden by 
a corresponding command line option. This worked fine for the update 
(building of stats db) run of AWstats but I had a boat load of trouble 
getting the awstats_buildstaticpages.pl script to behave in the same 
manner with the LogFile option. So, I called a round table meeting with 
my better judgment (who never showed up) and decided the only moral 
option was to hack at the config file with Perl each night--and change 
the damn LogFile location myself (s/day/day++/). So, below is the whole 
nine yards: (remember: Debian/Sarge, deb=awstats)

#!/usr/bin/perl -w

use strict;
use Date::Calc qw(Add_Delta_Days);

my $site = shift;
print "usage: $0 www.example.com\n" unless $site;

my ($DAY,$MONTH,$YEAR) = (localtime)[3,4,5];
my ($Y,$m,$d) = Add_Delta_Days($YEAR,$MONTH,$DAY,-1);
$Y += 1900;
$m += 1;
$m = '0'.$m if length($m) < 2;
$d = '0'.$d if length($d) < 2;

my $LOG_FILE = "/var/log/www/$site/$Y/$m/access.$m-$d-$Y.log";

my $ORIG_CONFIG = "/etc/awstats/awstats.$site.conf";
my $TEMP_CONFIG = "/etc/awstats/awstats.$site.conf.tmp";
open ORIG, "<$ORIG_CONFIG";
open TEMP, ">$TEMP_CONFIG";
for (<ORIG>) {
     chomp;
     ( my $tmp = $_ ) =~ s/^LogFile=.*$/LogFile=\"$LOG_FILE\"/g;
     print TEMP $tmp,"\n";
}
system("mv $TEMP_CONFIG $ORIG_CONFIG");

## update stats db (/var/log/awstats/):
print "processing $site access log from: $m-$d-$Y\n";
print "logfile: $LOG_FILE\n";
system("/usr/lib/cgi-bin/awstats.pl \\
         -config=$site \\
         -update ");

## cook stats html pages:
system ("perl 
/usr/share/doc/awstats/examples/awstats_buildstaticpages.pl \\
               -config=$site  \\
               -awstatsprog=/usr/lib/cgi-bin/awstats.pl \\
               -dir=/usr/local/www/data/$site/stats/");
system ("mv /usr/local/www/data/$site/stats/awstats.$site.html \\
             /usr/local/www/data/$site/stats/index.html");
system ("chgrp -R www-data /usr/local/www/data/$site/stats");




More information about the talk mailing list