Merging Awstats statistics via PHP-CLI

Because I previously hosted parts of this site on several subdomains, the Awstats crontab I ran on a daily basis used to generate separate statistics for each subdomain, too. As I had since merged all sub domains into one, subdomain-less site, I was looking into merging the old statistics for each month into one file per month, to make the old statistics reflect the new file structure as well, leading to more data I could use for comparisons. Unfortunately, I was unable to find couldn’t find a script that did just that, so I wrote my own.

So, here’s the deal: I wrote a PHP script containing three classes, to be used via PHP-CLI. The abstract class AwstatsFile is used as a generalizer for both the AwstatsFromFile class (reads an existing Awstats statistics file) and the AwstatsMerger class (merges instances of AwstatsFile). CLI arguments are the filenames to merge; the merged statistics file will be echoed to the output buffer, effectively STDOUT, and can be piped.

Let’s give an example. Say you have two Awstats statistics files awstats062010.aaronweb.net.txt and awstats062010.projects.aaronweb.net.txt, and the AwParse script as awparse.php. Assuming php is the binary for php-cli, you’d merge these files by executing:

$ php awparse.php awstats062010.www.aaronweb.net.txt awstats062010.projects.aaronweb.net.txt > awstats062010.aaronweb.net.txt

Without further ado, the file can be downloaded via the following link: awparse.php.

Suggestions and other comments are more than welcome! :)


No comments on 'Merging Awstats statistics via PHP-CLI' yet — be the first! (reply?)

Leave a Reply

(required)