generate_webstats.sh: supports generating statistics only for given site(s).
This commit is contained in:
parent
506644ef74
commit
85be34df84
@ -1,5 +1,16 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# - Script generates webalizer webstatistics
|
||||||
|
# -
|
||||||
|
# - usage: generate_webstats.sh [<site1> [<site2> ... ]]
|
||||||
|
# -
|
||||||
|
# - Webstatistics for the given sites will be created, where 'site<n>' must match
|
||||||
|
# - the 'HostName' parameter of the webalizer configuration.
|
||||||
|
# -
|
||||||
|
# - If no commandline is parameter given, statistics for all sites (which has a webalizer
|
||||||
|
# - configuration) will be generated.
|
||||||
|
# -
|
||||||
|
|
||||||
_src_base_dir="$(dirname $(realpath $0))"
|
_src_base_dir="$(dirname $(realpath $0))"
|
||||||
conf_file="${_src_base_dir}/conf/webalizer.conf"
|
conf_file="${_src_base_dir}/conf/webalizer.conf"
|
||||||
|
|
||||||
@ -23,6 +34,14 @@ clean_up() {
|
|||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## - Check if a given array (parameter 2) contains a given string (parameter 1)
|
||||||
|
## -
|
||||||
|
containsElement () {
|
||||||
|
local e
|
||||||
|
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
echononl(){
|
echononl(){
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo X\\c > /tmp/shprompt$$
|
echo X\\c > /tmp/shprompt$$
|
||||||
@ -37,25 +56,27 @@ echononl(){
|
|||||||
info (){
|
info (){
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*"
|
echo -e " [ \033[32m\033[1mInfo\033[m ]: $*"
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
warn (){
|
warn (){
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*"
|
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
||||||
echo ""
|
echo ""
|
||||||
else
|
else
|
||||||
echo "Warning: $*"
|
echo ""
|
||||||
|
echo "[ Warning ]: $*"
|
||||||
|
echo ""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
error(){
|
error(){
|
||||||
echo ""
|
echo ""
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*"
|
echo -e " [ \033[31m\033[1mFehler\033[m ]: $*"
|
||||||
else
|
else
|
||||||
echo "Error: $*"
|
echo "[ Error ]: $*"
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
@ -92,6 +113,17 @@ else
|
|||||||
terminal=false
|
terminal=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
declare -a given_site_arr
|
||||||
|
|
||||||
|
# - Is a site given on command line?
|
||||||
|
# -
|
||||||
|
if [[ $# -gt 0 ]]; then
|
||||||
|
for _site in "$@" ; do
|
||||||
|
given_site_arr+=("$_site")
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# -------------
|
# -------------
|
||||||
# --- Default values
|
# --- Default values
|
||||||
# -------------
|
# -------------
|
||||||
@ -112,13 +144,6 @@ fi
|
|||||||
|
|
||||||
_CACHE_FILE="${tmp_dir}/dns_cache.db"
|
_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
|
# - Check if script was invoked from logrotation script
|
||||||
# -
|
# -
|
||||||
@ -133,13 +158,19 @@ else
|
|||||||
invoked_from_logrotate=false
|
invoked_from_logrotate=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Generate web-statistics at host '$(hostname -f)'"
|
info "Generate web-statistics at host \033[1m$(hostname -f)\033[m"
|
||||||
|
|
||||||
while IFS='' read -r -d '' _conf_file ; do
|
while IFS='' read -r -d '' _conf_file ; do
|
||||||
|
|
||||||
_websites_log_file="$(grep -E "^\s*LogFile" $_conf_file | awk '{print$2}')"
|
_websites_log_file="$(grep -E "^\s*LogFile" $_conf_file | awk '{print$2}')"
|
||||||
_site="$(grep -e "^\s*HostName" $_conf_file | awk '{print$2}')"
|
_site="$(grep -e "^\s*HostName" $_conf_file | awk '{print$2}')"
|
||||||
|
|
||||||
|
|
||||||
|
if [[ ${#given_site_arr[@]} -gt 0 ]] ; then
|
||||||
|
containsElement "$_site" "${given_site_arr[@]}" || continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# - Warn if script was called from logrotation script
|
# - Warn if script was called from logrotation script
|
||||||
# -
|
# -
|
||||||
if $invoked_from_logrotate ; then
|
if $invoked_from_logrotate ; then
|
||||||
@ -156,8 +187,8 @@ while IFS='' read -r -d '' _conf_file ; do
|
|||||||
if [[ ! -s "${_websites_log_file}" ]] ; then
|
if [[ ! -s "${_websites_log_file}" ]] ; then
|
||||||
echo_skipped
|
echo_skipped
|
||||||
if ! $terminal ; then
|
if ! $terminal ; then
|
||||||
echo "[ Warning ]: No web-statistics for site '${_site}' generated!"
|
warn "No web-statistics for site '${_site}' generated!
|
||||||
echo " LogFile "${_websites_log_file}" not found or empty."
|
LogFile '${_websites_log_file}' not found or empty."
|
||||||
fi
|
fi
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user