alternc-awstats 1.91 KB
Newer Older
1 2
#!/bin/bash

3 4 5
# Called with no parameters, launch the daily awstats stats
# called with "all", launch all stats with all apache log files from /var/log/alternc/sites/
# called with a domain name, launch the stats for this domain from all apache log files 
6

7 8 9
cd /usr/lib/alternc 
# AlternC system functions
. ./functions.sh
10 11 12 13 14 15 16 17 18 19 20 21 22

# Regenerate the awstat etc cache files :
if [ -x ./awstats.cache.php ]
then
    ./awstats.cache.php
fi

CACHEDIR="/var/cache/awstats" # Dans la sarge par defaut les données awstats sont stockées dans /var/lib/awstats ...
mkdir -p $CACHEDIR

function searchdomain {
    U_ID=$(mysql_query "SELECT uid FROM aws WHERE hostname='$1'" | grep -v "^uid")
    U_LOGIN=$(mysql_query "SELECT login FROM membres WHERE uid='$U_ID'" |grep -v "^login")
23
    DOM_DIR="$ALTERNC_LOGS/$U_ID-$U_LOGIN"
24
    if [ -d "$DOM_DIR" ] ; then
Alan Garcia's avatar
Alan Garcia committed
25
        echo $(find -P "$DOM_DIR" -mindepth 1 -maxdepth 2 -type f -iname "*.log*" -print0 | xargs -0)
26
    fi
27 28 29 30 31 32
}

function dostatgz {
    read DOM
    while [ "$DOM" ]
    do
33
      echo -n "processing $DOM"
34
      LOGAPACHE=$(searchdomain $DOM)
35 36 37 38 39 40
      if [ -n "$LOGAPACHE" ] ; then
        echo " (for access files in $LOGAPACHE )"
        /usr/lib/cgi-bin/awstats.pl -config=$DOM -update -LogFile="/usr/lib/alternc/logresolvemerge.pl $LOGAPACHE* |"
      else
        echo "\n No log found"
      fi
41 42 43 44 45 46 47 48 49 50
      read DOM
    done
}

function dostat {
    read DOM
    while [ "$DOM" ]
    do
      echo "processing $DOM"
      LOGAPACHE=$(searchdomain $DOM)
51 52 53 54 55
      if [ -n "$LOGAPACHE" ] ; then
        /usr/lib/cgi-bin/awstats.pl -config=$DOM  -LogFile="/usr/lib/alternc/logresolvemerge.pl $LOGAPACHE | "
      else
        echo "No log found"
      fi
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
      read DOM
    done
}

if [ -z "$1" ]
    then
    mysql_query "SELECT hostname FROM aws" |grep -v "^hostname" | dostat
else
    if [ "$1" = "all" ]
	then
	mysql_query "SELECT hostname FROM aws" |grep -v "^hostname" | dostatgz
    else
	echo "$1" | dostatgz
    fi
fi