root/alternc-webalizer/tags/nightly_sarge/alternc-webalizer.manual.sh

Revision 1498, 1.9 kB (checked in by benjamin, 3 years ago)

erreur seq, voir man seq

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/bin/sh
2
3 if [ "$USER" != "www-data" ]
4 then
5     echo "Fatal : this script must be launched as www-data"
6     exit 1
7 fi
8
9 . /etc/alternc/local.sh
10
11 if [ -e /etc/alternc/webalizer.conf ]
12 then
13     . /etc/alternc/webalizer.conf
14 fi
15
16 if [ -z "$ACCESSLOG" ]
17 then
18     ACCESSLOG="/var/log/apache/access.log.1"
19 fi
20
21 if [ -z "$MYSQL_HOST" ]
22 then
23     MYSQL_HOST="localhost"
24 fi
25
26 # The regeneration is using a different cache directory
27 CACHEDIR="/tmp/alternc-webalizer"
28 TMPCACHE=`mktemp -p /tmp`
29
30 TMPLOG=`mktemp -p /tmp`
31 mkdir -p $CACHEDIR
32
33 trap cleanup 1 2 15
34
35 function cleanup {
36     rm -f $TMPLOG
37     rm -f $TMPCACHE
38     rm -rf $CACHEDIR/*
39 }
40
41 # Generate the cache dir :
42 /usr/lib/alternc/reset_stats_conf.php
43 rsync /var/cache/alternc-webalizer/ $CACHEDIR  -a
44
45 ACCESSDIR=`dirname $ACCESSLOG`
46
47 MAXFILE=`cd $ACCESSDIR; ls access.log.*.gz | sed -e 's/access.log.\(.*\).gz/\1/' | sort -g | tail -1`
48
49 function dostat {
50     read LANG DOM
51     while [ "$DOM" ]
52       do
53       # one day, we may delete old statistics for this member :
54       # but we need to
55       # 1. confirm
56       # 2. found the directory in the conf file.
57       # rm -f usage.png usage_*.html index.html hourly_usage_*.png daily_usage_*.png ctry_usage_*.png webalizer.current webalizer.hist
58
59       export LC_ALL="$LANG"
60       export LANG
61       export LC_MESSAGES="$LANG"
62       # first run: resolve IPs in cache
63       ( for i in `seq $MAXFILE -1 2` ; do zcat ${ACCESSDIR}/access.log.${i}.gz ; done ; cat ${ACCESSDIR}/access.log.1) | grep -h " $DOM$" | tee $TMPLOG | /usr/bin/webalizer -D $TMPCACHE -N 20 -c $CACHEDIR/$DOM.conf -
64      
65       # Second run : launch the stats
66       /usr/bin/webalizer -D $TMPCACHE -N 0 -c $CACHEDIR/$DOM.conf - <$TMPLOG 2>/dev/null
67       read LANG DOM
68     done
69 }
70
71 echo "Please enter the statistics you want to regenerate from gzipped apache logs."
72 echo "Enter one line per stat as follow : \"languagecode domain\" "
73
74 dostat
75
76 cleanup
Note: See TracBrowser for help on using the browser.