scripts/webalizer.sh

73 lines
1.5 KiB
Bash

#!/bin/sh
# webalizer cronjob
# 02/2007 ore
CONF_DIR=/etc/webalizer.d
WEBALIZER=/usr/bin/webalizer
[ -f ${WEBALIZER} ] || exit 0
for arg in "$@"; do
case "$arg" in
-h|--help)
echo "Usage: $0 [--help] [--verbose] [--purge]"
exit 0
;;
-v|--verbose)
VERBOSE="1"
;;
-p|--purge)
PURGE="1"
;;
*)
;;
esac
done
if [ "$VERBOSE" = "1" ]; then
WEBALIZER="$WEBALIZER -d"
fi
# for all configs
for config in $CONF_DIR/*.conf; do
[ "$VERBOSE" = "1" ] && echo "Using config '$config'"
logfile=$(awk '/^LogFile/{print $2}' $config)
outputdir=$(awk '/^OutputDir/{print $2}' $config)
# delete output directory, to regenerate all
[ "$PURGE" = "1" ] && {
[ "$VERBOSE" = "1" ] && echo " purging '$outputdir'"
rm -rf $outputdir
}
# output directory missing - create & parse *all* logs
[ -d ${outputdir} ] || {
[ "$VERBOSE" = "1" ] && echo " creating '$outputdir'"
mkdir -p $outputdir
# all logs in reversed order
for log in `ls -1tr ${logfile}.*.gz 2> /dev/null`; do
[ "$VERBOSE" = "1" ] && echo " parsing '$log'"
zcat $log | $WEBALIZER -c $config -q -
done
}
# rotated, not compressed logfile
[ -s ${logfile}.1 ] && {
[ "$VERBOSE" = "1" ] && echo " parsing '${logfile}.1'"
$WEBALIZER -c $config -q ${logfile}.1
}
# current logfile (as given in config)
[ -s ${logfile} ] && {
[ "$VERBOSE" = "1" ] && echo " parsing '${logfile}'"
$WEBALIZER -c $config -q
}
done