Analyze Apache log files from the command line
Sometime you just want to get a quick overview of what's going on. In this case I wanted to know from what regions accesses were made to a specific page. This web article: Analyzing Apache Log Files < System | The Art of Web, showed how to use awk to filter out specific fields in the apache log format.
I found some info on how to geolocate from the command line here: Geolocate a given IP address | commandlinefu.com (I installed geoip-bin on my Debian).
The resulting one-liner, that
- checks for a pattern in the log file vhosts_access.log,
- extracts the ip number for each request
- and geolocates it:
grep 'some_pattern_in_the_log' vhosts_access.log|awk '{print $2}'|sort|uniq| xargs -I xxx geoiplookup xxx|sort|less