Migrating from enXim and importing awstats data

DomineauX

Well-Known Member
PartnerNOC
Apr 12, 2003
429
11
168
Houston, TX
cPanel Access Level
Root Administrator
For those who migrate from enXim and are using the AwStats installation procedure that has been around for a long time prior to AwStats being built in to the product, the following script will handle importing of the AwStats historical data stored in /home/username/cgi-bin/awstats/data:


Code:
#!/bin/bash
for USERNAME in `/bin/ls -A /var/cpanel/users/`
do
    HOMEDIR=`grep "^$USERNAME:" /etc/passwd | awk -F: '{print $6}'`
    DOMAIN=`/bin/ls -A $HOMEDIR/tmp/awstats/ | grep -E "awstats\..*\.conf" | sed 's/awstats\.\(.*\)\.conf/\1/'`
    if [ -d $HOMEDIR/cgi-bin/awstats/data ]
    then
        for OLDFILE in `/bin/ls -A $HOMEDIR/cgi-bin/awstats/data`
        do
            NEWFILE=`echo $OLDFILE | sed "s/txt$/$DOMAIN\.txt/"`
            echo "mv $HOMEDIR/cgi-bin/awstats/data/$OLDFILE $HOMEDIR/tmp/awstats/$NEWFILE"
        done
    fi
done
Save this as something such as "awstats.sh" and then execute with "sh awstats.sh" and it will echo the "mv" commands for you to review.

If they look good, you can execute them directly from the awstats.sh output with "sh awstats.sh | sh"