linuxtips:awstatsmultidomainsetup [2012/01/14 05:08] mschiff Page moved from awstatsmultidomainsetup to linuxtips:awstatsmultidomainsetup |
linuxtips:awstatsmultidomainsetup [2012/01/14 05:12] (current) mschiff |
||
---|---|---|---|
Line 15: | Line 15: | ||
===== Template /etc/awstats/template ===== | ===== Template /etc/awstats/template ===== | ||
<code> | <code> | ||
- | - | + | # |
- | - domain specific settings | + | # domain specific settings |
- | - | + | # |
SiteDomain="%DOMAIN%" | SiteDomain="%DOMAIN%" | ||
Line 29: | Line 29: | ||
File: /etc/awstats/domain.conf.d/links2linux.de.conf | File: /etc/awstats/domain.conf.d/links2linux.de.conf | ||
<code> | <code> | ||
- | - awstats config for links2linux.de | + | # awstats config for links2linux.de |
AW_DOMAIN="links2linux.de" | AW_DOMAIN="links2linux.de" | ||
AW_ALIASES="wiki.links2linux.de" | AW_ALIASES="wiki.links2linux.de" | ||
Line 39: | Line 39: | ||
Whenever you change the template, the common or default settings you only have to run this script again to have fresh configs. | Whenever you change the template, the common or default settings you only have to run this script again to have fresh configs. | ||
<code> | <code> | ||
- | - !/bin/sh | + | #!/bin/sh |
- | - | + | # |
- | - create awstats configs | + | # create awstats configs |
- | - | + | # |
AW_SUPERUSER="awstats-root" | AW_SUPERUSER="awstats-root" | ||
find domain.conf.d/*.conf | while read CONFIG; do | find domain.conf.d/*.conf | while read CONFIG; do | ||
- | <code> | ||
. $CONFIG | . $CONFIG | ||
echo -n "Creating awstats.$AW_DOMAIN.conf ... " | echo -n "Creating awstats.$AW_DOMAIN.conf ... " | ||
Line 55: | Line 54: | ||
echo "# Include $f" >> awstats.$AW_DOMAIN.conf | echo "# Include $f" >> awstats.$AW_DOMAIN.conf | ||
echo "#" >> awstats.$AW_DOMAIN.conf | echo "#" >> awstats.$AW_DOMAIN.conf | ||
- | sed 's/#.*//;s/^[[|\t]]*//;s/[[|\t]]*$//' $f | sort -u >> awstats.$AW_DOMAIN.conf | + | sed 's/#.*//;s/^[[awstatsmultidomainsetup|\t]]*//;s/[[awstatsmultidomainsetup|\t]]*$//' $f | sort -u >> awstats.$AW_DOMAIN.conf |
done | done | ||
cat template \ | cat template \ | ||
Line 63: | Line 62: | ||
| sed "s|%USERS%|$AW_USER|" \ | | sed "s|%USERS%|$AW_USER|" \ | ||
>> awstats.$AW_DOMAIN.conf | >> awstats.$AW_DOMAIN.conf | ||
- | echo "OK"</code> | + | echo "OK" |
done | done | ||
</code> | </code> | ||
Line 73: | Line 72: | ||
This Script does this automatically: | This Script does this automatically: | ||
<code> | <code> | ||
- | - !/bin/sh | + | #!/bin/sh |
- | - | + | # |
- | - recreate awstats for a specific domain | + | # recreate awstats for a specific domain |
- | - | + | # |
- | - what does it do? | + | # what does it do? |
- | - | + | # |
- | - what we have: | + | # what we have: |
- | - - awstats for a sepcific timeframe, maybe much greater than 1 year | + | # awstats for a sepcific timeframe, maybe much greater than 1 year |
- | - - max last ~52 logfiles ~= 1 year | + | # max last ~52 logfiles ~= 1 year |
- | - | + | # |
- | - what we can do: | + | # what we can do: |
- | - 1) check for which timeframe we have logs now | + | # 1) check for which timeframe we have logs now |
- | - 2) remove awstats for that timeframe we detected in 1) | + | # 2) remove awstats for that timeframe we detected in 1) |
- | - 3) let awstats create stats from all logfiles | + | # 3) let awstats create stats from all logfiles |
DOMAIN="$1" | DOMAIN="$1" | ||
LOG="$2" | LOG="$2" | ||
- | - try to find LOG automatically if not defined | + | # try to find LOG automatically if not defined |
test "$LOG" || { | test "$LOG" || { | ||
- | <code> | ||
echo "Logfile not specified, trying to find it automatically (in domain.conf.d)" | echo "Logfile not specified, trying to find it automatically (in domain.conf.d)" | ||
- | if [[|-f domain.conf.d/$DOMAIN.conf ]]; then | + | if [[awstatsmultidomainsetup|-f domain.conf.d/$DOMAIN.conf ]]; then |
. domain.conf.d/$DOMAIN.conf | . domain.conf.d/$DOMAIN.conf | ||
- | if [[|"$AW_ACCESS_LOG" ]]; then | + | if [[awstatsmultidomainsetup|"$AW_ACCESS_LOG" ]]; then |
echo "Logfile found: $AW_ACCESS_LOG" | echo "Logfile found: $AW_ACCESS_LOG" | ||
LOG="$AW_ACCESS_LOG" | LOG="$AW_ACCESS_LOG" | ||
Line 103: | Line 101: | ||
echo "Nothing found" | echo "Nothing found" | ||
fi | fi | ||
- | fi</code> | + | fi |
} | } | ||
Line 114: | Line 112: | ||
DATA_DIR="/var/lib/awstats" | DATA_DIR="/var/lib/awstats" | ||
- | - 1) check which is the oldest monthe we have complete logs for | + | # 1) check which is the oldest monthe we have complete logs for |
OLDEST_LOG="$(ls -1 "$LOG"-* | head -1)" | OLDEST_LOG="$(ls -1 "$LOG"-* | head -1)" | ||
- | - we do not know when a domain started to exist | + | # we do not know when a domain started to exist |
- | - so we assume that the month from the oldest logline +1 is | + | # so we assume that the month from the oldest logline +1 is |
- | - the oldest month we have complete | + | # the oldest month we have complete |
- | - | + | # |
- | - (we take 'zless' here because it reads gzipped and unzipped files) | + | # (we take 'zless' here because it reads gzipped and unzipped files) |
OLDEST_LOGLINE="$(zless $OLDEST_LOG | head -n1)" | OLDEST_LOGLINE="$(zless $OLDEST_LOG | head -n1)" | ||
OLDEST_DATE_STRING="$(echo "$OLDEST_LOGLINE" | sed 's|.*\[[\(.*\)\]].*|\1|;s|/| |g;s/:/ /')" | OLDEST_DATE_STRING="$(echo "$OLDEST_LOGLINE" | sed 's|.*\[[\(.*\)\]].*|\1|;s|/| |g;s/:/ /')" | ||
Line 129: | Line 127: | ||
echo "Oldest logline is from $OLDEST_YEAR/$OLDEST_MONTH ($OLDEST_DATE_STRING)" | echo "Oldest logline is from $OLDEST_YEAR/$OLDEST_MONTH ($OLDEST_DATE_STRING)" | ||
- | if [[|"$OLDEST_MONTH" == "12" ]]; then | + | if [[awstatsmultidomainsetup|"$OLDEST_MONTH" == "12" ]]; then |
- | <code> | + | |
# set jan in the following year | # set jan in the following year | ||
OLDEST_COMPLETE_MONTH="01" | OLDEST_COMPLETE_MONTH="01" | ||
- | OLDEST_YEAR="$((OLDEST_YEAR+1))"</code> | + | OLDEST_YEAR="$((OLDEST_YEAR+1))" |
else | else | ||
- | <code> | + | if [[awstatsmultidomainsetup|"${OLDEST_MONTH:0:1}" == "0" ]]; then |
- | if [[|"${OLDEST_MONTH:0:1}" == "0" ]]; then | + | |
# remove leading zero | # remove leading zero | ||
OLDEST_MONTH=${OLDEST_MONTH:1:1} | OLDEST_MONTH=${OLDEST_MONTH:1:1} | ||
fi | fi | ||
OLDEST_COMPLETE_MONTH="$((OLDEST_MONTH+1))" | OLDEST_COMPLETE_MONTH="$((OLDEST_MONTH+1))" | ||
- | if [[|${#OLDEST_COMPLETE_MONTH} -eq 1 ]]; then | + | if [[awstatsmultidomainsetup|${#OLDEST_COMPLETE_MONTH} -eq 1 ]]; then |
# add leading zero | # add leading zero | ||
OLDEST_COMPLETE_MONTH="0$OLDEST_COMPLETE_MONTH" | OLDEST_COMPLETE_MONTH="0$OLDEST_COMPLETE_MONTH" | ||
- | fi</code> | + | fi |
fi | fi | ||
echo "So I assume oldest complete month is $OLDEST_YEAR/$OLDEST_COMPLETE_MONTH" | echo "So I assume oldest complete month is $OLDEST_YEAR/$OLDEST_COMPLETE_MONTH" | ||
Line 156: | Line 152: | ||
ls -1 $DATA_DIR/awstats[[0-9]][0-9][[0-9]][0-9][[0-9]][0-9].$DOMAIN.txt | while read AWSTAT; do | ls -1 $DATA_DIR/awstats[[0-9]][0-9][[0-9]][0-9][[0-9]][0-9].$DOMAIN.txt | while read AWSTAT; do | ||
- | <code> | ||
AWSTAT_YEAR="$(echo "$(basename $AWSTAT)" | sed 's/awstats[[0-9]]\{2\}\([[0-9]]\{,4\}\).*/\1/')" | AWSTAT_YEAR="$(echo "$(basename $AWSTAT)" | sed 's/awstats[[0-9]]\{2\}\([[0-9]]\{,4\}\).*/\1/')" | ||
AWSTAT_MONTH="$(echo "$(basename $AWSTAT)" | sed 's/awstats\([[0-9]]\{2\}\).*/\1/')" | AWSTAT_MONTH="$(echo "$(basename $AWSTAT)" | sed 's/awstats\([[0-9]]\{2\}\).*/\1/')" | ||
#echo "Found $AWSTAT (stats for $AWSTAT_YEAR/$AWSTAT_MONTH)" | #echo "Found $AWSTAT (stats for $AWSTAT_YEAR/$AWSTAT_MONTH)" | ||
- | if [[|$AWSTAT_YEAR -eq $OLDEST_YEAR ]]; then | + | if [[awstatsmultidomainsetup|$AWSTAT_YEAR -eq $OLDEST_YEAR ]]; then |
# same year | # same year | ||
- | if [[|$AWSTAT_MONTH -ge $OLDEST_COMPLETE_MONTH ]]; then | + | if [[awstatsmultidomainsetup|$AWSTAT_MONTH -ge $OLDEST_COMPLETE_MONTH ]]; then |
# same month or newer | # same month or newer | ||
echo "Deleting $AWSTAT" | echo "Deleting $AWSTAT" | ||
Line 168: | Line 163: | ||
fi | fi | ||
fi | fi | ||
- | if [[|$AWSTAT_YEAR -gt $OLDEST_YEAR ]]; then | + | if [[awstatsmultidomainsetup|$AWSTAT_YEAR -gt $OLDEST_YEAR ]]; then |
# newer year | # newer year | ||
echo "Deleting $AWSTAT" | echo "Deleting $AWSTAT" | ||
rm -f "$AWSTAT" | rm -f "$AWSTAT" | ||
- | fi</code> | + | fi |
done | done | ||
- | - now recreate logs | + | # now recreate logs |
- | - we must feed all logs to awstats in chronological order | + | # we must feed all logs to awstats in chronological order |
ls -1 "$LOG"-* | while read old_log; do | ls -1 "$LOG"-* | while read old_log; do | ||
- | <code> | ||
echo $old_log | egrep -q '\.gz$' && { | echo $old_log | egrep -q '\.gz$' && { | ||
zcat $old_log | zcat $old_log | ||
} || { | } || { | ||
cat $old_log | cat $old_log | ||
- | }</code> | + | } |
done | nice /usr/lib/cgi-bin/awstats.pl -config=$DOMAIN -update -showsteps -showcorrupted -showdropped -LogFile="-" | done | nice /usr/lib/cgi-bin/awstats.pl -config=$DOMAIN -update -showsteps -showcorrupted -showdropped -LogFile="-" | ||
- | - and current log | + | # and current log |
nice /usr/lib/cgi-bin/awstats.pl -config=$DOMAIN -update -showsteps -showcorrupted -showdropped | nice /usr/lib/cgi-bin/awstats.pl -config=$DOMAIN -update -showsteps -showcorrupted -showdropped | ||
Line 196: | Line 190: | ||
Calls the previous script for all domains | Calls the previous script for all domains | ||
<code> | <code> | ||
- | - !/bin/sh | + | #!/bin/sh |
- | - | + | # |
- | - recreate awstats for all known domains | + | # recreate awstats for all known domains |
- | - | + | # |
find domain.conf.d/*.conf | while read CONFIG; do | find domain.conf.d/*.conf | while read CONFIG; do | ||
- | <code> | ||
. $CONFIG | . $CONFIG | ||
- | ./recreate_stats.sh $AW_DOMAIN $AW_ACCESS_LOG</code> | + | ./recreate_stats.sh $AW_DOMAIN $AW_ACCESS_LOG |
done | done | ||
</code> | </code> | ||
- | --[[User:Mschiff|mschiff]] 17:02, 10 Jun 2005 (CEST) | + | --[[user:mschiff|mschiff]] 17:02, 10 Jun 2005 (CEST) |