Alternc  latest
Alternc logiel libre pour l'hébergement
alternc-awstats
Go to the documentation of this file.
1 #!/bin/bash
2 
3 # Called with no parameters, launch the daily awstats stats
4 # called with "all", launch all stats with all apache log files from /var/log/alternc/sites/
5 # called with a domain name, launch the stats for this domain from all apache log files
6 
7 cd /usr/lib/alternc
8 # AlternC system functions
9 . ./functions.sh
10 
11 # Regenerate the awstat etc cache files :
12 if [ -x ./awstats.cache.php ]
13 then
14  ./awstats.cache.php
15 fi
16 
17 CACHEDIR="/var/cache/awstats" # Dans la sarge par defaut les données awstats sont stockées dans /var/lib/awstats ...
18 mkdir -p $CACHEDIR
19 
20 function searchdomain {
21  U_ID=$(mysql_query "SELECT uid FROM aws WHERE hostname='$1'" | grep -v "^uid")
22  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
25  echo $(find -P "$DOM_DIR" -mindepth 1 -maxdepth 2 -type f -iname "*.log*" -print0 | xargs -0)
26  fi
27 }
28 
29 function dostatgz {
30  read DOM
31  while [ "$DOM" ]
32  do
33  echo -n "processing $DOM"
34  LOGAPACHE=$(searchdomain $DOM)
35  if [ -n "$LOGAPACHE" ] ; then
36  echo " (for access files in $LOGAPACHE )"
37  /usr/lib/cgi-bin/awstats.pl -config=$DOM -update -LogFile="/usr/lib/alternc/logresolvemerge.pl $LOGAPACHE* |"
38  else
39  echo "\n No log found"
40  fi
41  read DOM
42  done
43 }
44 
45 function dostat {
46  read DOM
47  while [ "$DOM" ]
48  do
49  echo "processing $DOM"
50  LOGAPACHE=$(searchdomain $DOM)
51  if [ -n "$LOGAPACHE" ] ; then
52  /usr/lib/cgi-bin/awstats.pl -config=$DOM -LogFile="/usr/lib/alternc/logresolvemerge.pl $LOGAPACHE | "
53  else
54  echo "No log found"
55  fi
56  read DOM
57  done
58 }
59 
60 if [ -z "$1" ]
61  then
62  mysql_query "SELECT hostname FROM aws" |grep -v "^hostname" | dostat
63 else
64  if [ "$1" = "all" ]
65  then
66  mysql_query "SELECT hostname FROM aws" |grep -v "^hostname" | dostatgz
67  else
68  echo "$1" | dostatgz
69  fi
70 fi
71