Plesk awstats rebuild script


Recent updates to Plesk has resulted in older installations still running awstats from breaking. Attempts to correct this has required me to create this script. also check your “icons” alias in the http conf files.

#!/bin/bash
#
# 2016-04-05
# Build awstats files correctly.
# Latest Plesk update has blown the configuration and
# no longer builds the awsatts files as needed.
#
WEBDIR=/var/www/vhosts/system
#
# Path to awstats PERL program
#
AWPATH=/usr/share/awstats/wwwroot/cgi-bin
#
# site specific config files
#
SITECONFDIR=/usr/local/psa/etc/awstats
#
# YYYY-MM formatted
#
MONTH=`date '+%Y-%m'`
#
# type of files to OUTPUT
#
TYPES=(alldomains allhosts allrobots browserdetail downloads errors400 errors403 errors404 keyphrases keywords lasthosts lastrobots osdetail refererpages refererse session unknownbrowser unknownip unknownos urldetail urlentry urlexit)
 
        for CONFFILE in `ls ${SITECONFDIR}/awstats.*-http.conf`
        do
                DOMAIN=`echo $CONFFILE | cut -d'.' -f2- | cut -d'-' -f1`
                for OUTTYPE in ${TYPES[@]}
                do
                        TARGET="awstats.${DOMAIN}-http.${OUTTYPE}.html"
                        perl ${AWPATH}/awstats.pl -config=${CONFFILE} -update
                        perl ${AWPATH}/awstats.pl -config=${CONFFILE} -output=${OUTTYPE} > ${WEBDIR}/${DOMAIN}/statistics/webstat/${MONTH}/${TARGET}
                done
                perl ${AWPATH}/awstats.pl -config=${CONFFILE} -output > ${WEBDIR}/${DOMAIN}/statistics/webstat/${MONTH}/index.html
        done