egscripts/egstats/awstats-static.sh

147 lines
3.6 KiB
Bash
Raw Normal View History

#!/bin/bash
#
# create static XHTML pages for statistics for a given awstats config
#
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=""
RESULTS=""
LOG="/var/log/awstats-static.log"
NICE="19"
#
# functions to put content into an index.html file...
starthtml() {
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 STRICT//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> " > $HTMLFILE
echo "<html>" >> $HTMLFILE
echo " <head>" >> $HTMLFILE
SITETITLE="Site statistics for $CONFIG"
echo " <title>$SITETITLE</title>" >> $HTMLFILE
echo " </head>" >> $HTMLFILE
echo " <body>" >> $HTMLFILE
echo " <h1>$SITETITLE</h1>" >> $HTMLFILE
echo " <p>Index of statistics by year and month</p>" >> $HTMLFILE
echo " <ul style=\"\">" >> $HTMLFILE
}
startyear() {
echo " <li style=\"\">Statistics for $YEAR:" >> $HTMLFILE
echo " <ul>" >> $HTMLFILE
}
addmonth() {
MONTHNAME=${MONTH[$M]}
echo "MONTHNAME = $MONTHNAME"
echo " <li style=\"\"><a href=\"$YEAR/$MM/index.html\">$MONTHNAME</a></li>" >> $HTMLFILE
}
endyear() {
echo " </ul>" >> $HTMLFILE
echo " </li>" >> $HTMLFILE
}
endhtml() {
echo " </ul>" >> $HTMLFILE
echo " </body>" >> $HTMLFILE
echo "</html>" >> $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
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