Home / Overriding the AWStats LogFile Configuration Option

Overriding the AWStats LogFile Configuration Option

I run AWStats on one of my servers and it copies files over from some of the other servers I manage every 15 minutes and processes them. However, I had a server issue yesterday with the machine that AWStats runs on, and it meant the auto process which copies the files over and runs AWStats stopped running for about 12 hours.

The end result was that data from the remote server wasn’t processed from 6:30pm last night. It started again early this morning with today’s log files, but this meant anything from 6:30pm last night to midnight wasn’t included in the AWStats data. In order to fix this I needed to remove the current month’s AWStats data file and then regenerate the stats.

The way I have this particular server configured is to have a separate log file for each day of the month; after clearing out this month’s data I needed to run AWStats again for each log file. Fortunately it’s still early in the month so there aren’t too many of them 🙂

The AWStats configuration files contain directives for where the log file is stored, and look something like this:


# "LogFile" contains the web, ftp or mail server log file to analyze.
# Possible values: A full path, or a relative path from awstats.pl directory.
# Example: "/var/log/apache/access.log"
# Example: "../logs/mycombinedlog.log"
# You can also use tags in this filename if you need a dynamic file name
# depending on date or time (Replacement is made by AWStats at the beginning
# of its execution). This is available tags :
[snip]
LogFile="/path/to/filename.%YYYY-1%MM-1%DD-1.log"

My LogFile setting uses the "tags" function and it gets translated to the format filename.YYYYMMDD where YYYY, MM and DD are the year, month and day respectively of the previous hour. So between midnight and 1am it will process yesterday’s file and the rest of the day the current day’s file.

In order to regenerate the stats for the month to date, I need to change the LogFile directive for each log file and process them sequentially. It would be a pain having to edit the log file, run the update command, edit the log file, run the update command and so on, so instead it is possible to pass the LogFile on the command line and override the setting in the configuration file.

A normal invocation of the AWStats update command might look like this:


/path/to/awstats.pl -update -config=myconfig

where "myconfig" is the name of the AWStats configuration to use. To override the LogFile directive you simply add -LogFile=name_of_file like so:


/path/to/awstats.pl -update -config=myconfig -LogFile=/path/to/name_of_file

Obviously if you are running the command from the directory where the log files are stored then you don’t need to pass the full path, and you can specify relative paths etc as well.

I had to run this command 7 times, once for each log file for the month to date. However, I could have saved myself a little time and done this instead, using a nice little bash trick:

for i in 01 02 03 04 05 06 07;
do
  /path/to/awstats.pl -update -config=myconfig -LogFile=filename.200709$i.log  
done