Skip to content

Instantly share code, notes, and snippets.

@alexchantavy
Created September 1, 2014 15:45
Show Gist options
  • Save alexchantavy/fe3d408ef53d346d2130 to your computer and use it in GitHub Desktop.
Save alexchantavy/fe3d408ef53d346d2130 to your computer and use it in GitHub Desktop.
Geolocate nginx visitors
#!/bin/sh
# Geolocate nginx site visitors with geoiplookup.
# Output format = <IP> <Date> <Request> <City of IP>
NGINX_LOG_FILE=/my/log/file/here
cat $NGINX_LOG_FILE | awk '{print $1, $4, $5, $6, $7}' |
while read p ; do
set -- $p
echo "$p ["`geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat "$1" | awk '{print $6, $7, $8, $9, $10, $11}'`"]";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment