zcat to the rescue

Today I was trying to figure out how many people were looking at what on our intranet (there’s a word I haven’t heard in a long time). Anyhow… apache has a lot of Gzipped files in the logs and I know about cat… but the last thing I wanted to do was unzip all of the log files just to find which PHP files someone hit.

{ cat resources_access.log intranet_access.log.1 2>/dev/null; zcat resources_access.log.*.gz 2>/dev/null; } | awk '{print $7}' | grep '\.php' | sort | uniq -c | sort -rn | head -50

Using this code on our intranet logfiles I was quickly able to see that… well not many people are using the tools.

Author: Miyar Es