iEFdev

Code, Computers & Random Junk

Script to Update GeoIP.dat

Here’s a small script to update your GeoIP database file(s).

Save this file as: geoipupd in a folder within PATH. I saved mine in /usr/httpd/sbin/geoipupd - same folder as apachectl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash
#
# /usr/httpd/sbin/geoipupd
#
# Script to update GeoIP databases
#

# Run as root
[[ $EUID -ne 0 ]] && echo "This script must be run as root" 1>&2 && exit 1;

# GeoIP.dat
_geoip='http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz'

# GeoLiteCity.dat
_geocity='http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz'

ERROR=0

cd /usr/local/share/GeoIP

for file in ${_geoip} ${_geocity}; do
  wget -qc --limit-rate=30k ${file}
  gzip -d -f $(basename ${file});
  ERR=$?

  [ $ERROR == 0 ] && echo "$(basename $0): $(basename ${file}) is updated.";
done

exit $ERROR;

2016-07-02: Updated the script.

Edit the paths to match your configuration/installation.

Notes:

  • I’ve set the rate limit to 30k. My internet speed s**ks, so I don’t want anything to grab all of it.
  • To use it - just run the command once in a while, or put it in a crontab. On OS X, make a LaunchDaemon to run once a month, or something like that.

Comments