I had to count traffic made by a resource from the apache log files. If awstats had been installed it would have been an easy job, but it wasn’t hard without it either. I used hints from here to build the following:
[cce_bash]
awk ‘{ s += $10 } END { print “Total “, s/1024/1024 ” MB”, “- Average “, s/NR/1024/1024 ” MB”, “- Access “, NR }’ access_log
[/cce_bash]
This prints a result like this:
[cce_bash]
Total 28.4232 MB – Average 0.0108485 Mo – Access 2620
[/cce_bash]
If you need to search for a particular date:
[cce_bash]
grep “02/Mar” access_log | awk ‘{ s += $10 } END { print “Total “, s/1024/1024 ” MB”, “- Average “, s/NR/1024/1024 ” MB”, “- Access “, NR }’
[/cce_bash]
If you need to search for a particular resource:
[cce_bash]
grep “silly_large_cat_picture.jpg” access_log | awk ‘{ s += $10 } END { print “Total “, s/1024/1024 ” MB”, “- Average “, s/NR/1024/1024 ” MB”, “- Access “, NR }’
[/cce_bash]
Of course you can combine:
[cce_bash]
grep “silly_large_cat_picture.jpg” access_log | grep “02/Mar” | awk ‘{ s += $10 } END { print “Total “, s/1024/1024 ” MB”, “- Average “, s/NR/1024/1024 ” MB”, “- Access “, NR }’
[/cce_bash]