#!/bin/bash # # create and index for static XHTML pages of awstats statistics # YEARS="2003 2004 2005" MS="1 2 3 4 5 6 7 8 9 10 11 12" MONTH[1]=January MONTH[2]=February MONTH[3]=March MONTH[4]=April MONTH[5]=May MONTH[6]=June MONTH[7]=July MONTH[8]=August MONTH[9]=September MONTH[10]=October MONTH[11]=November MONTH[12]=December AWSDIR="/usr/local/awstats/" AWSTOOL="$AWSDIR/tools" AWSROOT="$AWSDIR/wwwroot" CONFDIR="/etc/awstats" CMD="$AWSTOOL/awstats_buildstaticpages.pl" ARGS="-update -staticlinksext=html" MODE="help" CONFIG="" RESULTDIR="" LOG="/var/log/awstats-static.log" NICE="19" # # functions to put content into an index.html file... starthtml() { echo " " > $HTMLFILE echo "" >> $HTMLFILE echo " " >> $HTMLFILE SITETITLE="Site statistics for $CONFIG" echo " $SITETITLE" >> $HTMLFILE echo " " >> $HTMLFILE echo " " >> $HTMLFILE echo "

$SITETITLE

" >> $HTMLFILE echo "

Index of statistics by year and month

" >> $HTMLFILE echo " " >> $HTMLFILE echo " " >> $HTMLFILE echo "" >> $HTMLFILE } # # function to direct a message... message() { echo "$0: $TIMESTAMP $@" >> $LOG } # # insert a blank line into the log and on the console insert_blank() { echo "" >> $LOG } # # get command line args while test $# -ne 0 ; do case $1 in --config|-c) shift CONFIG=$1 ;; --results|-r) shift RESULTS=$1 ;; --help|?|-h) shift MODE="help" ;; esac shift done # # check for mode if test -z $CONFIG -o -z $RESULTS ; then MODE="help" else MODE="run" fi if test $MODE == "run" ; then DIRS=`/usr/bin/find $REPORTS -name "??" -type d` echo "using config in $CONFDIR/awstats.$CONFIG.conf, putting results into $RESULTS" if test -d $RESULTS ; then HTMLFILE="$RESULTS/index.html" starthtml fi for YEAR in $YEARS do startyear YEARDIR=$RESULTS/$YEAR if test ! -d $YEARDIR ; then echo "creating new year directory: $RESULTS/$YEAR" mkdir $YEARDIR fi for M in $MS do MM=$(echo $M|sed -e 's/^.$/0&/') MONTHDIR=$RESULTS/$YEAR/$MM if test ! -d $MONTHDIR ; then echo "creating new month directory: $MONTHDIR" mkdir $MONTHDIR fi addmonth if test -d $DIR ; then # run the awstats command to build the files for that month nice -n $NICE $CMD $ARGS -config=$CONFIG -month=$MM -year=$YEAR -dir=$MONTHDIR 2>&1 > /dev/null # link the basic xml file to an index.html... mv $MONTHDIR/awstats.$CONFIG.xml $MONTHDIR/index.html echo "running test on month $MM, year $YEAR" else echo "Couldn't find $DIR! Exiting" exit 1 fi done endyear done endhtml else echo "$0, copyright 2005 Egressive Limited, www.egressive.com" echo "" echo "Usage: $0 {-c config -r results_path | -h}" echo "-r or --results - the absolute path to the directory" echo " to populate with the year/month/ XHTML results files" echo "-c or --config - the AWSTATS configuration name, probably" echo " in /etc/awstats - the name is awstats.[name].conf" echo "-h or --help - this help message" fi exit 0