Posts Tagged ‘uniq’

Top 50 Squid

Tuesday, March 3rd, 2009

Pour avoir le top 50 des sites visités.

cat /var/log/squid/access.log |grep -v -e DENIED | awk ‘{ print $7}’ | sed ’s_http://\([^/]*\)/.*_ \1  _g’ |  sort | uniq -c | sort -gr | head -n 50

explication de texte :

Format du log :Apache

192.XX.XX1.XX2 - - [03/Mar/2009:16:58:28 +0100] “POST http://www.csuivi.courrier.laposte.fr/default.asp HTTP/1.1″ 0 0 TCP_MISS:DIRECT
192.0.1.132 - - [03/Mar/2009:16:58:28 +0100] “POST http://www.csuivi.courrier.laposte.fr/default.asp HTTP/1.1″ 200 7031 TCP_MISS:DIRECT

Cat : Facile

grep -v : exclue les pages bloquées

awk : affiche le 7e argument de la ligne traitée ex: http://www.csuivi.courrier.laposte.fr/default.asp

sed : extrait l’adresse du serveur ex: www.csuivi.courrier.laposte.fr

sort : trie

uniq -c : compte le nombre d’occurances

sort : trie par nombre d’occurance

head -n 50 : Top 50