#!/bin/sh
# /etc/cron.daily/webalizer: webalizer daily maintenance script
# Written by Remco van de Meent
WEBALIZER_BIN=/usr/bin/webalizer
WEBALIZER_CONF_DIR=/etc/webalizer
# See if the webalizer binary and config dir exists
# if not, exit without warning to prevent daily mails
[ -f ${WEBALIZER_BIN} ] || exit 0
[ -d ${WEBALIZER_CONF_DIR} ] || exit 0
for WEBALIZER_CONF in $WEBALIZER_CONF_DIR/*.conf
do
# Figure out non-rotated logfile
nonrotatedlog=`egrep '^LogFile' $WEBALIZER_CONF | \
sed -e 's/[[:space:]]\+/ /' | \
cut -d ' ' -f2 | \
sed -e 's/\.[[:digit:]][\.gz]*$//'`
# Can we read it?
[ -r "${nonrotatedlog}" ] || continue
# Check for empty logfile
logsz=`echo ${nonrotatedlog} | \
sed -e 's/[[:space:]]\+/ /' | \
cut -d ' ' -f2 | \
xargs ls -l | \
sed -e 's/[[:space:]]\+/ /g' | \
cut -d ' ' -f5`
[ $logsz -gt 0 ] || continue
# Run webalizer quietly
${WEBALIZER_BIN} -c ${WEBALIZER_CONF} -q
${WEBALIZER_BIN} -c ${WEBALIZER_CONF} -q ${nonrotatedlog}
done
# Exit with webalizer's exit code
exit $?
#!/bin/sh
# /etc/cron.daily/webalizer: webalizer daily maintenance script
# Written by Remco van de Meent
WEBALIZER_BIN=/usr/bin/webalizer
WEBALIZER_CONF=/etc/webalizer.conf
APACHE_VHOST_CONFDIR=/etc/apache/vhosts.d
# See if the webalizer binary and config dir exists
# if not, exit without warning to prevent daily mails
[ -f ${WEBALIZER_BIN} ] || exit 0
[ -f ${WEBALIZER_CONF} ] || exit 0
[ -d ${APACHE_VHOST_CONFDIR} ] || exit 0
for CONFIG in `ls ${APACHE_VHOST_CONFDIR}/* -1 | grep -v 'Main.conf'`
do
SITE=`grep -v '^[[:space:]]*#' $CONFIG | \
grep -m1 'ServerName' | \
sed 's/^[[:space:]]*//' | \
sed 's/[[:space:]]\+/ /' | \
cut -d ' ' -f2`
DIR=`grep -v '^[[:space:]]*#' $CONFIG | \
grep -m1 'DocumentRoot' | \
sed 's/^[[:space:]]*//' | \
sed 's/[[:space:]]\+/ /' | \
cut -d ' ' -f2`
LOG=`grep -v '^[[:space:]]*#' $CONFIG | \
grep -m1 'CustomLog' | \
sed 's/^[[:space:]]*//' | \
sed 's/[[:space:]]\+/ /' | \
cut -d ' ' -f2`
OPTS="-n $SITE -t $SITE -o $DIR/webalizer"
# TODO: HideSite and HideReferrer are missing!
# Can we read the log files?
[ -r "$LOG" ] || continue
[ -r "$LOG.1" ] || continue
# Check for empty log files
logsz=`ls -l $LOG | \
sed -e 's/[[:space:]]\+/ /g' | \
cut -d ' ' -f5`
[ $logsz -gt 0 ] || continue
logsz=`ls -l "$LOG.1" | \
sed -e 's/[[:space:]]\+/ /g' | \
cut -d ' ' -f5`
[ $logsz -gt 0 ] || continue
# Run webalizer quietly
${WEBALIZER_BIN} -c ${WEBALIZER_CONF} -q $OPTS "$LOG"
${WEBALIZER_BIN} -c ${WEBALIZER_CONF} -q $OPTS "$LOG.1"
done
# Exit with webalizer's exit code
exit $?