#!/usr/bin/env bash _src_base_dir="$(dirname $(realpath $0))" conf_file="${_src_base_dir}/conf/webalizer.conf" tmp_dir="$(mktemp -d)" log_file="$(mktemp)" # ------------- # - Functions # ------------- clean_up() { # Perform program exit housekeeping rm -f "$log_file" rm -rf "$tmp_dir" if $terminal ; then echo "" fi exit $1 } echononl(){ if $terminal ; then echo X\\c > /tmp/shprompt$$ if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then echo -e -n "$*\\c" 1>&2 else echo -e -n "$*" 1>&2 fi rm /tmp/shprompt$$ fi } info (){ if $terminal ; then echo "" echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" echo "" fi } warn (){ if $terminal ; then echo "" echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" echo "" else echo "Warning: $*" fi } error(){ echo "" if $terminal ; then echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*" else echo "Error: $*" fi echo "" } echo_done() { if $terminal ; then echo -e "\033[75G[ \033[32mdone\033[m ]" fi } echo_failed(){ if $terminal ; then echo -e "\033[75G[ \033[1;31mfailed\033[m ]" fi } echo_skipped() { if $terminal ; then echo -e "\033[75G[ \033[37mskipped\033[m ]" fi } # ------------- # --- Check some prerequisites # ------------- # - Running in a terminal? # - if [[ -t 1 ]] ; then terminal=true else terminal=false fi # ------------- # --- Default values # ------------- DEFAULT_WEBALSIZER_BINARY="/usr/local/webalizer/bin/webalizer" DEFAULT_WEBALSIZER_CONF_DIR="/usr/local/webalizer/etc" # ------------- # --- Read Configurations from $conf_file # ------------- if [[ -f "$conf_file" ]]; then source "$conf_file" fi [[ -n "$WEBALSIZER_BINARY" ]] || WEBALSIZER_BINARY="$DEFAULT_WEBALSIZER_BINARY" [[ -n "$WEBALSIZER_CONF_DIR" ]] || WEBALSIZER_CONF_DIR="$DEFAULT_WEBALSIZER_CONF_DIR" _CACHE_FILE="${tmp_dir}/dns_cache.db" #/bin/rm -f ${TMP_DIR}/$CACHE_FILE # #for i in /var/log/apache/*.log; do # # /usr/local/webalizer/bin/webazolver -Q -o ${TMP_DIR} -N20 -D $CACHE_FILE $i # #done # - Check if script was invoked from logrotation script # - # - Note: Its the parent of the parent # - _stat=($( $log_file 2>&1 if [[ $? -ne 0 ]]; then if ! $terminal ; then echo "[ Error ]: Generatin webstatistics for site '${_site}' failed!" fi echo_failed error "$(cat "$log_file")" else echo_done fi done < <(find "${WEBALSIZER_CONF_DIR}" -maxdepth 1 -type f -name "*.conf" -print0) clean_up 0