| 1 | #!/bin/sh |
| 2 | # /etc/cron.daily/webalizer: Webalizer daily maintenance script |
| 3 | # This script was originally written by |
| 4 | # Remco van de Meent <remco@debian.org> |
| 5 | # and now, all rewrited by Jose Carlos Medeiros <jose@psabs.com.br> |
| 6 | |
| 7 | # This script just run webalizer against all .conf files in /etc/webalizer directory |
| 8 | |
| 9 | WEBALIZER=/usr/bin/webalizer |
| 10 | WEBALIZER_CONFDIR=/etc/webalizer |
| 11 | |
| 12 | [ -x ${WEBALIZER} ] || exit 0; |
| 13 | [ -d ${WEBALIZER_CONFDIR} ] || exit 0; |
| 14 | |
| 15 | for i in ${WEBALIZER_CONFDIR}/*.conf; do |
| 16 | # exists ? |
| 17 | [ -f $i ] || continue; |
| 18 | |
| 19 | # run agains a rotated or normal logfile |
| 20 | LOGFILE=`awk '$1 ~ /^LogFile$/ {print $2}' $i`; |
| 21 | |
| 22 | # empty ? |
| 23 | [ -s "${LOGFILE}" ] || continue; |
| 24 | # readable ? |
| 25 | [ -r "${LOGFILE}" ] || continue; |
| 26 | |
| 27 | # there was a output ? |
| 28 | OUTDIR=`awk '$1 ~ /^OutputDir$/ {print $2}' $i`; |
| 29 | # exists something ? |
| 30 | [ "${OUTDIR}" != "" ] || continue; |
| 31 | # its a directory ? |
| 32 | [ -d ${OUTDIR} ] || continue; |
| 33 | # its writable ? |
| 34 | [ -w ${OUTDIR} ] || continue; |
| 35 | |
| 36 | # Run Really quietly, exit with status code if !0 |
| 37 | ${WEBALIZER} -c ${i} -Q || continue; |
| 38 | RET=$?; |
| 39 | |
| 40 | # Non rotated log file |
| 41 | NLOGFILE=`awk '$1 ~ /^LogFile$/ {gsub(/\.[0-9]+(\.gz)?/,""); print $2}' $i`; |
| 42 | |
| 43 | # check current log, if last log is a rotated logfile |
| 44 | if [ "${LOGFILE}" != "${NLOGFILE}" ]; then |
| 45 | # empty ? |
| 46 | [ -s "${NLOGFILE}" ] || continue; |
| 47 | # readable ? |
| 48 | [ -r "${NLOGFILE}" ] || continue; |
| 49 | |
| 50 | ${WEBALIZER} -c ${i} -Q ${NLOGFILE}; |
| 51 | RET=$?; |
| 52 | fi; |
| 53 | done; |
| 54 | |
| 55 | # exit with webalizer's exit code |
| 56 | exit $RET; |
| 57 | |