#!/bin/bash # # create static XHTML pages for statistics for a given awstats config # 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" # # work out dates MM=`date -d "last month" +%m` MONTH=`date -d "last month" +%B` YEAR=`date -d "last month" +%Y` # # 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 echo "using config in $CONFDIR/awstats.$CONFIG.conf, putting results into $RESULTS" if test -d $RESULTS ; then HTMLFILE="$RESULTS/index.html" fi YEARDIR=$RESULTS/$YEAR if test ! -d $YEARDIR ; then echo "creating new year directory: $RESULTS/$YEAR" mkdir $YEARDIR fi MONTHDIR=$RESULTS/$YEAR/$MM if test ! -d $MONTHDIR ; then echo "creating new month directory: $MONTHDIR" mkdir $MONTHDIR fi if test -d $MONTHDIR ; then # run the awstats command to build the files for that month echo "running test on month $MM, year $YEAR" 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 else echo "Couldn't find $DIR! Exiting" exit 1 fi 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