scripts/webalizer.sh

73 lines
1.5 KiB
Bash
Raw Normal View History

2006-07-27 12:00:28 +02:00
#!/bin/sh
# webalizer cronjob
2007-02-09 10:42:00 +01:00
# 02/2007 ore
2006-07-27 12:00:28 +02:00
CONF_DIR=/etc/webalizer.d
WEBALIZER=/usr/bin/webalizer
[ -f ${WEBALIZER} ] || exit 0
2007-02-09 10:42:00 +01:00
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
2007-02-11 13:40:06 +01:00
if [ "$VERBOSE" = "1" ]; then
WEBALIZER="$WEBALIZER -d"
fi
2006-07-27 12:00:28 +02:00
# for all configs
for config in $CONF_DIR/*.conf; do
2007-02-09 10:42:00 +01:00
[ "$VERBOSE" = "1" ] && echo "Using config '$config'"
2006-07-27 12:00:28 +02:00
logfile=$(awk '/^LogFile/{print $2}' $config)
outputdir=$(awk '/^OutputDir/{print $2}' $config)
2007-02-09 10:42:00 +01:00
# delete output directory, to regenerate all
[ "$PURGE" = "1" ] && {
[ "$VERBOSE" = "1" ] && echo " purging '$outputdir'"
rm -rf $outputdir
}
2006-07-27 12:00:28 +02:00
# output directory missing - create & parse *all* logs
[ -d ${outputdir} ] || {
2007-02-09 10:42:00 +01:00
[ "$VERBOSE" = "1" ] && echo " creating '$outputdir'"
2006-07-27 12:00:28 +02:00
mkdir -p $outputdir
2007-02-09 10:42:00 +01:00
# 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
2006-07-27 12:00:28 +02:00
}
# rotated, not compressed logfile
2006-10-01 13:47:07 +02:00
[ -s ${logfile}.1 ] && {
2007-02-09 10:42:00 +01:00
[ "$VERBOSE" = "1" ] && echo " parsing '${logfile}.1'"
$WEBALIZER -c $config -q ${logfile}.1
2006-07-27 12:00:28 +02:00
}
# current logfile (as given in config)
2006-10-01 13:47:07 +02:00
[ -s ${logfile} ] && {
2007-02-09 10:42:00 +01:00
[ "$VERBOSE" = "1" ] && echo " parsing '${logfile}'"
$WEBALIZER -c $config -q
2006-07-27 12:00:28 +02:00
}
done