I’ve created a small shellscript that allows the administrator to build log statistics for multiple domain names.
You can download the script to generate statistics from multiple log files awstats_generate_multiple_sites.sh from here .
The usage of the script is quite self explanatory. You have to follow the instructions in the commented head of the script.
After you have properly configured the script all you have to do is set it to be executed via crontab.
Again in the script head I’ve included information with an example on how to add it to a crontab. The script takes all subdirectories from /var/log/apache2 assuming that each of the subdirectories contains access.log and error.log file names.
It generates a number of configuration files to be later red by awstats and after finishing, invokes awstats to generate the statistics from the previously generated awstats domain configuration files.
Finally the script generates an html files with links to each of the domains for whom awstats has generated statistics.
The idea for the script hit me, before a week time, after I’ve red an article which explains how to achieve something similar to what the script does manually.
You can read the article configuring multiple awstats for multiple domain on dreamhost here . I believe the script can be quite useful to the administrators out there who are looking for a quick way to generate awstats statistics from their many domain log files.
Cheers! 🙂
More helpful Articles
Tags: apache, awstats, generate, multiple, statistics
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0
I modified your script so I would not have to setup individual logs for each site as they are dynamically created using aegir.
1.Setup cron (run crontab -e or add a file in /etc/cron.d)
# split access.log into domainlogs/domainname.log
5,15,25,35,45,55 * * * * root cd /var/log/apache2/domainlogs; /usr/sbin/split-logfile /dev/null
2.Create script file (nano /usr/lib/cgi-bin/my.sh)
loop_dir=/var/log/apache2/domainlogs;
index_page=/var/www/test.html;
title=”ESSDACK.org Statistics”;
css_file=”style.css”;
awstats_location=”/usr/lib/cgi-bin/awstats.pl”;
awstats_conf=”/etc/awstats/awstats.conf”;
awstats_url=”http://stats.goosewing.essdack.org/statistics/awstats.pl?config”;
# create an empty page
cat /dev/null > $index_page;
# add html tags to top of page
echo “$title
$title” >> $index_page;
echo “” >> $index_page;
echo “Awstats web statistics for:” >> $index_page;
# find all domains by log file
for i in $(echo $loop_dir/*); do
# check that its a file and not a dir -f (http://www.linuxtutorialblog.com/post/tutorial-conditions-in-bash-scripting-if-statements#file-based-conditions)
if [ -f “$i” ]; then
filename=$(basename $i);
extension=${filename##*.}
domain_name=${filename%.*}
#echo “full path = $i; filename = $filename; extension = $extension; domain = $domain”;
echo “Generating Awstats file for: $domain_name”;
# create /etc/awstats/awstats.$domain.conf file
sed -e “s#SiteDomain=\”\”#SiteDomain=\”$domain_name\”#g” -e “s#LogFile=\”\”#LogFile=\”$i\”#g” $awstats_conf > /etc/awstats/awstats.”$domain_name”.conf;
[ -x $awstats_location -a -f $awstats_conf -a -r $i ] && $awstats_location -config=awstats -update >/dev/null
# run sudo /usr/lib/cgi-bin/awstats.pl -config=$domain -update
[ -x $awstats_location -a -f /etc/awstats/awstats.”$domain_name”.conf -a -r $i ] && $awstats_location -config=”$domain_name” -update
# add links for web sites stat page
echo “ $domain_name ” >> $index_page;
fi
done
# add html tags to bottom of page
echo “” >> $index_page;
3.set permissions on file (chmod 755 /user/lib/cgi-bin/my.sh
View CommentView Comment4. have fun
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0
the site cut out some of the crontab and script, will post to another site and make link sometime.
View CommentView CommentMozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+ Debian/squeeze (2.30.6-1) Epiphany/2.30.6
great nice script,
View CommentView Commentthanks!