So if you have installed AWstats, a web-statistic program, on your machine you would have noticed that the cron job that it sets by default does not work. Meaning that the statistics on your AWstats web page does not get updated. If you do a search on Internet, you will find that lot of Ubuntu and Debian folks are facing the same problem. Also there are lot of other suggestions (but dangerous) that are given to make it work, but I have found the following solution to the most (but not completely) safest of all.

Let’s first take a look at the cron job that gets installed by default when you install AWstats in Debian Lenny:

debian:~# cat /etc/cron.d/awstats
0,10,20,30,40,50 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.conf -a -r /var/log/apache2/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=mydomain.org -update>/dev/null

Now if you read the Debian specific README file at:
/usr/share/doc/awstats/README.Debian

it will say giving proper “read” permission to access.log file at /var/log/apache2/. Now even after giving read permission to that file, the “www-data” user is not able to access the apache log files. You can verify this by running the following command:
debian:~# sudo -u www-data /usr/bin/perl /usr/lib/cgi-bin/awstats.pl -update -config=mydomain.org

Output:
Create/Update database for config "/etc/awstats/awstats.mydomain.org.conf" by AWStats version 6.7 (build 1.892)
From data in log file "/var/log/apache2/access.log"...
Error: Couldn't open server log file "/var/log/apache2/access.log" : Permission denied
Setup ('/etc/awstats/awstats.mydomain.org.conf' file web server or permissions) may be wrong.
Check config file permissions and AWStats documentation (in 'docs' directory).
debian:~#

That’s right, even after giving read permission to access.log file, it still cannot read it.

After a lot of researching I finally tried the following command:

# chmod 755 -R /var/log/apache2/*

The above command makes the files “readable” and “executable” for the group “adm” and for “others” user.

Now the cron job, /etc/cron.d/awstats, will execute just fine you should be able to see your server’s statistics at:

http://mydomain.org/awstats/awstats.pl

Also if anyone of you find a better solution than above, please post it in the comment section below.

Happy CRON’ing!

Be Sociable, Share!