Webalizer With a Dash of Logrotate

Recently I decided to stop using Google Analytics for my website traffic analysis. Yes, it's still probably the best analytics tool out there but I actually don't care about details that much. The only thing I care about is trend - is site getting better or worse - and nothing much else. For that purpose, a simple Webalizer setup would do.

My Webalizer setup was actually as close to plain as it gets. The only trick up my sleeve was that I had a separate configuration file for each of my sites. Of course, since I use logrotate to split my Apache traffic logs, I also needed to add a bit of prerotate action into the /etc/logrotate.conf to ensure I don't miss any entries.

My first try was this:

for FILE in /srv/configs/**/webalizer.conf
/usr/bin/webalizer -c $FILE

And, while this did wonders from command line, it seemed to do absolutely nothing when executed by logrotate itself. Reason for its misbehavior was that logrotate (and crontab) uses sh as its shell and not bash.

To get around this, a Posix-compatible command is needed:

find /srv/configs/ -name "webalizer.conf" -exec /usr/bin/webalizer -c {} \;

This now executes just before my Apache log file gets rotated-out and Webalizer gets one last chance to catch-up with its stats.

Leave a Reply

Your email address will not be published. Required fields are marked *