Weblog entry #11 for lee
I'm setting up awstats to process multiple domains, and outputting to static html files. A previous article concerning generating website statistics provides instruction on outputting static reports, and suggests modifying awstats-update for multiple configs.
So in order to run monthly reports, available from a URL such as "http://stats.example.com/stats/example.org/2005/12/awstats.example.org.html", I have created a script to run as a monthly cron job.
#!/bin/sh
## specific months can be specified on command line, eg " 2005 01"
WEBDIR=/var/www/stats
#WEBDIR=/srv/web/stats.example.com/docs/stats
if [ -n "$1" ]
then YEAR=$1
else YEAR=`date +%Y --date="1 month ago"`
fi
if [ -n "$2" ]
then MONTH=$2
else MONTH=`date +%m --date="1 month ago"`
fi
for cfg in `find /etc/awstats -name 'awstats.*.conf' -printf '%f\n' | sed 's/^awstats\.\(.*\)\.conf/\1/'`; do
mkdir -p $WEBDIR/$cfg/$YEAR/$MONTH
/usr/share/doc/awstats/examples/awstats_buildstaticpages.pl \
-awstatsprog=/usr/lib/cgi-bin/awstats.pl \
-year=$YEAR -month=$MONTH \
-dir=$WEBDIR/$cfg/$YEAR/$MONTH/ \
-config=$cfg > /dev/null
done