Awstats autoupdate via cron

Haven

Verified User
Joined
Sep 22, 2005
Messages
5
Location
York, UK
Hi Guys

I noticed that the awstats plugin doesn't have the option to automatically update periodically so I wrote a quick script that you can plug into cron to do this. Hopefully someone will find it useful, just slap this code into a file and refer to it from within cron.

In order for this script to work you need to keep your slocate database up to date, if you don't do this already then you will need to do so.

Code:
#!/bin/bash

#static variables
awstats_updateall="/usr/local/directadmin/plugins/awstats/hooks/cgi-bin/awstats_updateall.pl"
awstats_config_dir="/etc/awstats/"

# 1)grab a list of all installed awstats by looking for config files in /etc/awstats:
# 2)seperate out the domain names

for x in /etc/awstats/awstats.*.conf
do
    if [ $x != "/etc/awstats/awstats.default.conf" ]; then
       #extract the first three sections of a domainname from the listed files in /etc/awstats/
       domainname=`echo $x | awk -F / '/awstats/ {print $4}' | awk -F . '// {print $2"."$3"."$4}'`
       #find the awstats file for this domain using the extracted parts above:
       awstats_executable=`slocate -r /home/.*/${domainname}.*/.*/awstats.pl$`
       #check that we have all the required pieces of information:
       if [ -x $awstats_executable  ]
          then
          runme="$awstats_updateall now -awstatsprog=$awstats_executable -configdir=$awstats_config_dir"
       fi
       #finally run the stats
       $runme
    fi
done
 
Last edited:
Why use another script if the original one already does all the updating :s


/usr/local/directadmin/plugins/awstats/hooks/cgi-bin/awstats_updateall.pl now -awstatsprog=/usr/local/directadmin/plugins/awstats/hooks/cgi-bin/awstats.pl
 
I honestly didnt know about the original - nevermind it was a good excercise to go through anyway :)
 
Back
Top