-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-awstats
executable file
·60 lines (50 loc) · 1.42 KB
/
update-awstats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
set -eux
shopt -s nullglob
cd $(dirname "$0")
BASE=$(pwd)
CONFIGDIR=$BASE/cgi-bin
DATADIR=$BASE/data
LOGSDIR=$HOME/logs
mkdir -p $DATADIR
function write_config {
cat > $CONFIG_PATH <<ENDCONFIG
DirData="$DATADIR"
Include "$BASE/awstats.common.conf"
LogFile="$1"
SiteDomain="$SITE"
HostAliases="www.$SITE"
UseHTTPSLinkForUrl="$HTTPSLINKS"
ENDCONFIG
if [[ -f $LOCAL_CONFIG_PATH ]]
then
cat $LOCAL_CONFIG_PATH >> $CONFIG_PATH
fi
}
for LOG in $(find $LOGSDIR/*/http{s,}/access.log -mtime -31)
do
[[ "$LOG" =~ logs/(.+)/(http|https) ]]
SITE=${BASH_REMATCH[1]}
PROTOCOL=${BASH_REMATCH[2]}
case $PROTOCOL in
https) CONFIG=${SITE} ; HTTPSLINKS='/' ;;
*) CONFIG=${SITE}-${PROTOCOL} ; HTTPSLINKS='' ;;
esac
CONFIG_PATH=$CONFIGDIR/awstats.$CONFIG.conf
LOCAL_CONFIG_PATH=$BASE/awstats.$CONFIG.conf
if [ -f "$LOGSDIR/$SITE/$PROTOCOL/access.log.0" ]
then
LOGALLCMD="cd $LOGSDIR/$SITE/$PROTOCOL && zcat -f access.log.2* access.log |"
LOGDAYCMD="cd $LOGSDIR/$SITE/$PROTOCOL && cat access.log.0 access.log |"
else
LOGALLCMD="cd $LOGSDIR/$SITE/$PROTOCOL && cat access.log |"
LOGDAYCMD="cd $LOGSDIR/$SITE/$PROTOCOL && cat access.log |"
fi
case ${1:-all} in
all) write_config "$LOGALLCMD" ;;
day) write_config "$LOGDAYCMD" ;;
esac
$BASE/awstats/wwwroot/cgi-bin/awstats.pl -configdir=$CONFIGDIR -config=$CONFIG -update
# Rewrite config with all logs to better support rawlog searches
write_config "$LOGALLCMD"
done