#!/bin/sh
#
# this script generates the overnight and cumulative web access
# statistic reports using /httpd/tools/analog/analog.
#
# this script is run from the cron, as root because it has to
# stop and restart the httpd process.
sets="/httpd/logs /kxxx/admin /kyyy/admin"
# the sets variable defines where the various input and output
# files for analog can be found. every set element should point
# to a directory with these input files:
#
# access_log (must be the real thing, not a symlink)
# error_log (must be the real thing, not a symlink)
# analog.cache (used for cumulative reports, created if not present)
# analog.conf (used to override analog defaults)
#
# for archiving purposes, two subdirectories are also required.
# they are automatically created if not present.
#
# logs/ (subdirectory for archived logs)
# stats/ (subdirectory for archived stats)
#
# given the above, analog will produce these output files.
# you are responsible to link to the HTML output or otherwise
# export them to the httpd document tree.
#
# access_log.gz (archived and dated under logs/)
# error_log.gz (archived and dated under logs/)
# analog.cache (new cumulative cache)
# stats.html (overnight stats)
# stats-$date$ (archived under stats/)
# stats-all.html (cumlulative stats)
cache=analog.cache
config=analog.conf
analog="/httpd/tools/analog/analog +g$config"
gzip=/usr/bin/gzip
today=`date +%b%d` # rolls over yearly
umask 022
/httpd/bin/apachectl stop # stop the current httpd so we can
# move and rename the logs cleanly.
for set in $sets
do
cd $set
mv access_log access_log-$today
mv error_log error_log-$today
if [ ! -d logs ]; then mkdir logs; fi
if [ ! -d stats ]; then mkdir stats; fi
done
/httpd/bin/apachectl start # restart httpd before we start the
# lengthy report process.
for set in $sets
do
cd $set
# generate and archive overnight report
$analog access_log-$today > stats.html
cp stats.html stats/stats-${today}.html
# generate cumulative cache and report
$analog +U$cache +C"OUTPUT CACHE" access_log-$today > new.cache
mv analog.cache analog.cache.bak
mv new.cache analog.cache
$analog +U$cache +m +D -h /dev/null > stats-all.html
# compress and archive logs
$gzip access_log-$today
$gzip error_log-$today
mv access_log-${today}.gz error_log-${today}.gz logs/
done