AlternC/awstats/alternc-awstats

74 lines
2.0 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# Appelé seul, lance les stats AWStats du jour.
# Appelé avec "all" lance les stats avec tous les fichiers .gz situés dans /var/log/apache
# Appelé avec un nom de domaine en paramètre, rescanne tous les fichiers .gz pour ce domaine uniquement.
# Include some usefull functions
. /usr/lib/alternc/functions.sh
# Regenerate the awstat etc cache files :
if [ -x ./awstats.cache.php ]
then
./awstats.cache.php
fi
# FIXME : set this var in local.sh
LOG_DIR="/var/alternc/logs"
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")
DOM_DIR="$LOG_DIR/$U_ID-$U_LOGIN"
if [ -d "$DOM_DIR" ] ; then
echo $(find -P "$DOM_DIR" -mindepth 1 -maxdepth 2 -type f -iname "*.log" -print0 | xargs -0)
fi
}
function dostatgz {
read DOM
while [ "$DOM" ]
do
echo -n "processing $DOM"
LOGAPACHE=$(searchdomain $DOM)
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
read DOM
done
}
function dostat {
read DOM
while [ "$DOM" ]
do
echo "processing $DOM"
LOGAPACHE=$(searchdomain $DOM)
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
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