#!/bin/bash # # create static XHTML pages for statistics for a given awstats config # AWSDIR="/usr/share/awstats" AWSTOOL="$AWSDIR/tools" #AWSROOT="/var/www/cgi-bin/wwwroot" CONFDIR="/etc/egscripts/egawstats/awstatsconf" CMD="$AWSTOOL/awstats_buildstaticpages.pl" #ARGS="-update -awstatsprog=/var/www/cgi-bin/awstats.pl" ARGS="-update -awstatsprog=/var/www/cgi-bin/awstats.pl" # # set defaults MODE="help" CONF="" RESULTS="" LOG="/var/log/egawstats.log" NICE="19" # # work out dates thismonth() { MM=`date +%m` MONTH=`date +%B` YEAR=`date +%Y` } # # function to direct a message... message() { TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'` echo "$0: $TIMESTAMP $@" >> $LOG } # # insert a blank line into the log and on the console insert_blank() { echo "" >> $LOG } # # work out dates lastmonth() { MM=`date -d "last month" +%m` MONTH=`date -d "last month" +%B` YEAR=`date -d "last month" +%Y` } # # choose a default just to be safe thismonth # # get command line args # start log with a blank line... insert_blank while test $# -ne 0 ; do case $1 in --config|-c) shift CONF=$1 ;; --results|-r) shift RESULTS=$1 ;; --this) thismonth message "getting details for current month ($MONTH $YEAR)" ;; --last) lastmonth message "getting details for last month ($MONTH $YEAR)" ;; --help|?|-h) MODE="help" ;; esac shift done # # check for mode message "$CONF and $RESULTS" if [ -z $CONF -o -z $RESULTS ] ; then MODE="help" else MODE="run" fi if test $MODE == "run" ; then #message "using config in $CONFDIR/awstats.$CONF.conf, putting results into $RESULTS" YEARDIR=$RESULTS/$YEAR if ! test -d $YEARDIR ; then message "creating new year directory: $RESULTS/$YEAR" mkdir $YEARDIR fi # if test -d $YEARDIR ; then # nice -n $NICE $CMD $ARGS -config=$CONF -month=all -year=$YEAR -dir=$YEARDIR 2>&1 > /dev/null # # link the basic xml file to an index.html... # ln -sf $YEARDIR/awstats.$CONF.html $YEARDIR/index.html # fi MONTHDIR=$YEARDIR/$MM if ! test -d $MONTHDIR ; then message "creating new month directory: $MONTHDIR" mkdir $MONTHDIR fi if test -d $MONTHDIR ; then # run the awstats command to build the files for that month #message "running test on month $MM, year $YEAR" nice -n $NICE $CMD $ARGS -config=$CONF -month=$MM -year=$YEAR -dir=$MONTHDIR 2>&1 > /dev/null # $CMD $ARGS -config=$CONF -month=$MM -year=$YEAR -dir=$MONTHDIR # link the basic xml file to an index.html... ln -sf $MONTHDIR/awstats.$CONF.html $MONTHDIR/index.html else message "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 --last | --this | -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