#!/bin/bash # # gen_hist - generate a v2.20 history file from html pages # # Description: # # This script will scan a directory of Webalizer usage reports and # create a history file from them for use with v2.20 of the Webalizer. # It uses the GNU tools 'grep', 'sed', and 'sort', and should work # on any GNU/linux based system. This script is only required if you # have more than 12 months of reports and would like the new version # to display them in the main index (since it can now display up to # 10 years worth of history). # # Usage: # # Copy this script to whatever directory you have your webalizer # reports in.. this is the directory where all the usage_YYYYMM.html # files are (among others). Then simply type: # # ./gen_hist > new.hist # # to generate a new history file named "new.hist". Examine the file # to verify everything went as expected. If it did, you can then # either copy or rename it to webalizer.hist. The next time you run # the webalizer, the new history file will be used and the months in # it will appear on the main index page that gets generated. It is # of course recomended that you backup up your existing history file, # just in case something does go wrong. # # Note: If your reports do not display the daily totals, the first # and last day of the month values will be forced to 1 and 31, which # will cause incorrect average values. If this applies to you, you # probably should edit the generated history file and put in the real # numbers unless the averages are unimportant to you. # # # Modification History # # Date Who What # ----------- --- ----------------------------------------- # 09-Jun-2008 BLB Original script # 11-Jun-2008 BLB Add check for DAYSTATS (use 1/31 if none) # # # print descriptive header echo "# Webalizer V2.20 History Data - generated by 'gen_hist'" # Loop through files for i in usage_*; do #strip out our values YEAR=`echo $i | sed "s/usage_//g" | sed "s/..\.html//g"` MONTH=`echo $i | sed "s/usage_....//g" | sed "s/\.html//g"` HITS=`grep "Total Hits" -A1 $i | tail -1 | sed "s/.*//g" | sed "s/<\/B.*//g"` FILES=`grep "Total Files" -A1 $i | tail -1 | sed "s/.*//g" | sed "s/<\/B.*//g"` PAGES=`grep "Total Pages" -A1 $i | tail -1 | sed "s/.*//g" | sed "s/<\/B.*//g"` VISITS=`grep "Total Visits" -A1 $i | tail -1 | sed "s/.*//g" | sed "s/<\/B.*//g"` XFER=`grep "Total KBytes" -A1 $i | tail -1 | sed "s/.*//g" | sed "s/<\/B.*//g"` SITES=`grep "Total Unique Sites" -A1 $i | tail -1 | sed "s/.*//g" | sed "s/<\/B.*//g"` FDAY=`grep "DAYSTAT" $i` if [ "$FDAY" = "" ]; then FDAY=1; LDAY=31; else FDAY=`grep "Daily Statistics for" -A10 $i | tail -1 | sed "s/.*//g" | sed "s/<\/B.*//g"` LDAY=`grep "NAME=.HOURSTAT" -B16 $i | head -1 | sed "s/.*//g" | sed "s/<\/B.*//g"` fi # spit out a line of history in proper format echo "$MONTH $YEAR $HITS $FILES $SITES $XFER $FDAY $LDAY $PAGES $VISITS" # when done, sort-n-exit done | sort -k2nr -k1nr