AWK: quick way to get squid users traffic usage

If you need quick and simple way to get squid users traffic usage you can use this script:

#!/bin/bash
awk '{
user =  $8
traffic[user] += $5;
}
END {
OFS = "tt"
for (i in traffic) {printf "%s - tt size:  %10.2f Mbn", i, ( traffic[i] /  (1024 * 1024 ) ) }
}' | column -t | sort -rnk4

Here is an example:

[root@server ~]# head -n 50000 /var/log/squid/access.log | /usr/local/bin/traf.sh
alice - size: 1532.08 Mb
linda - size: 11.84 Mb
cray - size: 9.30 Mb
focus - size: 3.05 Mb
santa - size: 0.96 Mb
[root@server ~]#

Note! It will work only for users with authorization!

Didn’t find the answer to your question? Ask it our administrators to reply we will publish on website.

Leave a Reply

Your email address will not be published. Required fields are marked *