Script to correct missing AWStats statistics on Plesk

The Plesk statistics system doesn’t use any log data from previous months. If you need to regenerate statistics for previous months, you can use this script. Make sure that the logs are uncompressed in the statistics/logs directory for the domain and then run this script from within the domain’s root directory (eg. /var/www/vhosts/example.com):

#!/bin/bash
# per http://kb.parallels.com/en/5550

# make sure to enter the actual domain name on the next line:
export vhost_name=ENTER-REAL-DOMAIN-NAME-HERE

export AWSTATS_BIN_D=`grep ^AWSTATS_BIN_D /etc/psa/psa.conf | awk '{print $2}'`
export HTTPD_VHOSTS_D=`grep ^HTTPD_VHOSTS_D /etc/psa/psa.conf | awk '{print $2}'`
export PRODUCT_ROOT_D=`grep ^PRODUCT_ROOT_D /etc/psa/psa.conf | awk '{print $2}'`
export awstats=${AWSTATS_BIN_D}/awstats.pl
export awstats_gen_opts="-staticlinks -configdir=${PRODUCT_ROOT_D}/etc/awstats -config=${vhost_name}-http"

find $HTTPD_VHOSTS_D/$vhost_name/statistics/webstat -name '*.txt' -exec rm -f '{}' \;

$awstats $awstats_gen_opts -LogFile=$HTTPD_VHOSTS_D/${vhost_name}/statistics/logs/access_log.processed

# for both of these loops, change the year range to match those that need to be regenerated:

for y in 2007 2008 2009; do for m in `seq 1 12` ; do mkdir ${HTTPD_VHOSTS_D}/${vhost_name}/statistics/webstat/$y-$(printf "%.2d" $m) ; done ; done

for y in 2007 2008 2009; do \
 for m in `seq -w 1 12` ; do \
     dest_dir=$HTTPD_VHOSTS_D/$vhost_name/statistics/webstat/$y-$m ; \
     $awstats $awstats_gen_opts -month=$m -year=$y -output > $dest_dir/awstats.${vhost_name}-http.html ; \
     ln -s $dest_dir/awstats.${vhost_name}-http.html $dest_dir/index.html ; \
     for output in alldomains allhosts lasthosts unknownip allrobots lastrobots session urldetail urlentry urlexit osdetail unknownos refererse refererpages keyphrases keywords errors404 ; do \
         $awstats $awstats_gen_opts -month=$m -year=$y -output=$output > $dest_dir/awstats.${vhost_name}-http.$output.html ; \
     done ; \
 done ; \
done

$PRODUCT_ROOT_D/admin/sbin/statistics --calculate-one --domain-name=$vhost_name

This is based on the information in this Parallels KB: http://kb.parallels.com/en/5550

Posted in System Admin. Tags: , . RSS. Trackback.

Leave a Reply