- Ce script permet aux utilisateurs dont le serveur web est apache de récupérer les logs concernants leur site, et d'en extraire des statistiques.
- Copier le script ci-dessous dans un fichier stt
- Modifier les variables SITENAME, LOGNAME, PASSWD, myIP.
- Créer un répertoire stat
- Lancer la commande 'bash stt get' pour récupérer les logs
- Lancer la commander 'bash stt' pour lancer l'annalyse des logs
- Visualiser le résultat avec votre browser: fichier stat/stat.html.
#!/bin/bash
SITENAME="FTP SERVER"
LOGNAME="login"
PASSWD="password"
myIP="MON IP ADDRESS"
if test $# -eq 1 && test "$1" = "get" ; then
echo " ftp the log ..."
ftp -n $SITENAME << FIN
user $LOGNAME $PASSWD
cd logs
prompt
mget *.log
FIN
echo "Now process it: bash stt "
exit 0
fi
# so process it
for i in $(ls *.log) ; do
nfn=$(head -n 1 $i | cut -d\[ -f2 | cut -d\: -f1 | tr "/" " " |
awk '{
a["Jan"]="01"; a["Feb"]="02"; a["Mar"]="03";
a["Apr"]="04"; a["May"]="05"; a["Jun"]="06";
a["Jul"]="07"; a["Aug"]="08"; a["Sep"]="09";
a["Oct"]="10"; a["Nov"]="11"; a["Dec"]="12";
print $3"_"a[$2]"_"$1;
}')
echo $i "->" $nfn
fn="stat/${nfn}.stt"
if test -f $fn ; then
echo $fn " already done"
rm $i
continue
fi
exec 3>&1
exec 1> $fn
echo "<H2>$(date -d "$(echo $nfn |tr "_" "/")" +"%A %d %B %Y")</H2>"
echo "<H3>"
echo "- pagesVues $(fgrep -e "htm" -e " / " $i|grep -v $myIP |wc -l)"
echo "<BR>"
echo "- visites " $(sort -u +0 -1 $i | grep -v $myIP | wc -l)
echo "</H3>"
for p in $(sort -u +0 -1 $i | grep -v $myIP | cut -d\ -f1); do
pn=$(nslookup $p | awk '/^Name/{print $2}')
echo "<BR><BR><TABLE width="90%" border=1>"
echo "<TR><TD width=70%>$p @ <B>$pn</B></TD>"
deb=$(fgrep $p $i |head -n 1|cut -d\: -f2,3,4|cut -d\ -f1)
fin=$(fgrep $p $i |tail -n 1|cut -d\: -f2,3,4|cut -d\ -f1)
echo "<TD align=center width=20%> $deb - $fin </TD><TD>"
echo $(fgrep -e "htm" -e " / " $i | fgrep $p | wc -l)
echo "</TD></TR><TR><TD colspan=2> "
echo $(fgrep -e "htm" -e " / " $i |fgrep $p|cut -d\" -f2|cut -d\ -f2)
echo "</TD></TR></TABLE>"
done
exec 1>&-
exec 1>&3
rm $i
done
npV=0
nV=0
cd stat
exec 1> "stat.html"
echo "<HTML><HEAD><TITLE>Stat $SITENAME</TITLE></HEAD><BODY>"
echo "<TABLE><TR><TD colspan=4 ></TD>"
echo "<TD width=200 align=center>PageVue</TD>"
echo "<TD width=200 align=center>Visite</TD></TR>"
for i in $(ls -r *.stt); do
dt=$(date -d "$( echo ${i%.stt} | tr "_" "/" )"
+"<TD>%A</TD><TD>%d</TD><TD>%B</TD><TD>%Y</TD>")
pV=$(grep pagesVue $i | cut -d\ -f4)
V=$(grep visite $i | cut -d\ -f4)
let npV=npV+pV
let nV=nV+V
echo "<TR>$dt<TD align=center>$pV</TD>"
echo "<TD align=center><A HREF=$i>$V</A></TD></TR>"
done
echo "<TR><TD colspan=4 align=center><B>Total</B>"
echo "</TD><TD align=center><B>"
echo "$npV</B></TD><TD align=center><B>$nV</B></TD></TR>"
echo "</TABLE>"
echo "<HR width=80%><TABLE>"
cat *.stt |
sed "s/main.html/main.htm/g" |
sed "s/\/ /\/index.html /g" |
sed "s/\/$/\/index.html /g" |awk '
BEGIN { myIP=0 }
/htm/ {
split($0,a)
for ( i in a ) {
b[a[i]]++
}
delete a
}
END {
for ( i in b )
print b[i] " " i
}' | sort -bnr | awk '{print "<TR><TD>"$2"</TD><TD>"$1"</TD></TR>"}'
stat de log apache : micro annuaire
| cygwin | : | le compilateur gcc sous windows ainsi que tous les outils unix (awk, grep, sed, bash, ksh ...). |
| Youhp3 | : | Youpee est un preprocesseur HTML pour vous simplifier toutes les tâches répétitives dans la création d'un site web. Salemioche.net utilise trés largement ses possibilités. |