Pejman Moghadam / Scripts

Return code counter for Squid access.log

Public domain


#!/bin/bash
echo "Wait ..."
TMP=$(mktemp)
LOG="/usr/local/squid/var/logs/access.log"
[ -e $TMP ] && rm $TMP
COUNT=1
for CODE in $( (bzcat $LOG-*.bz2 ; cat $LOG) | awk '{print $4}' | sort | uniq)
do
  NUM=$( (bzcat $LOG-*.bz2 ; cat $LOG) | grep "$CODE"  | wc -l)
  echo "$NUM : $CODE" >> $TMP
  echo -n -e "\xd ${COUNT}:${CODE}                         "
  COUNT=$(( $COUNT + 1 ))
done
echo -e "\xd                                               "
echo
sort -n -r $TMP
[ -e $TMP ] && rm $TMP

Output

56483 : TCP_MISS/200
44411 : TCP_HIT/200
31978 : TCP_CLIENT_REFRESH_MISS/503
28453 : TCP_NEGATIVE_HIT/503
17358 : TCP_IMS_HIT/304
17165 : TCP_MEM_HIT/200
16910 : TCP_MISS/000
9651 : TCP_MISS/206
8978 : TCP_MISS/403
5573 : TCP_MISS/302
4083 : TCP_REFRESH_UNMODIFIED/200
3946 : TCP_NEGATIVE_HIT/403
3789 : TCP_REFRESH_UNMODIFIED/304
2627 : TCP_CLIENT_REFRESH_MISS/200
2477 : TCP_MISS/404
2099 : TCP_NEGATIVE_HIT/404
1877 : TCP_MISS/304
1747 : TCP_MISS/204
1721 : TCP_HIT/206
1423 : TCP_CLIENT_REFRESH_MISS/206
1295 : TCP_CLIENT_REFRESH_MISS/403
992 : TCP_NEGATIVE_HIT/502
834 : TCP_MISS/503
737 : TCP_MISS/502
690 : TCP_MISS/504
520 : TCP_MISS/301
456 : TCP_NEGATIVE_HIT/400
433 : NONE/400
379 : TCP_REFRESH_MODIFIED/200
374 : TCP_CLIENT_REFRESH_MISS/000
293 : TCP_HIT/000
279 : TCP_CLIENT_REFRESH_MISS/304
273 : TCP_MISS/401
236 : TCP_HIT/301
235 : TCP_MEM_HIT/301
195 : TCP_MISS/408
165 : TCP_REFRESH_MODIFIED/302
148 : TCP_NEGATIVE_HIT/204
104 : TCP_MISS/500
86 : TCP_CLIENT_REFRESH_MISS/404
71 : TCP_MEM_HIT/302
45 : TCP_MISS/303
31 : TCP_MEM_HIT/206
30 : TCP_CLIENT_REFRESH_MISS/204
29 : TCP_MISS/400
27 : TCP_IMS_HIT/200
20 : TCP_NEGATIVE_HIT/500
19 : TCP_REFRESH_FAIL/200
10 : TCP_DENIED/403
10 : TCP_CLIENT_REFRESH_MISS/502
7 : TCP_MISS/416
6 : TCP_REFRESH_UNMODIFIED/206
6 : TCP_CLIENT_REFRESH_MISS/500
4 : TCP_REFRESH_MODIFIED/403
4 : TCP_CLIENT_REFRESH_MISS/301
3 : TCP_REFRESH_MODIFIED/206
3 : TCP_MISS/710
3 : TCP_CLIENT_REFRESH_MISS/302
2 : TCP_REFRESH_FAIL/302
1 : TCP_REFRESH_FAIL/502
1 : TCP_REFRESH_FAIL/206
1 : TCP_MISS/841
1 : TCP_MISS/603
1 : TCP_MISS/501
1 : TCP_MISS/410
1 : TCP_MEM_HIT/410
1 : TCP_HIT/410
1 : TCP_CLIENT_REFRESH_MISS/504
1 : TCP_CLIENT_REFRESH_MISS/400

BY: Pejman Moghadam
TAG: squid, access-log, bash, bash-script
DATE: 2011-10-14 17:43:23


Pejman Moghadam / Scripts [ TXT ]