≡ Menu

Shell Script To Update MaxMind GeoIP Database

First, you need to install MaxMind C Api including geoipupdate utility.

Second, configure /usr/local/etc/GeoIP.conf file with your LicenseKey, UserId and ProductIds. A sample config file:

UserId 424242
LicenseKey zLzIYFYENTZOyAyNdSdWbEoR42
ProductIds 106

Put the following script at – /etc/cron.monthly/updategeoip.sh (cron job)

#!/bin/bash
# Shell Script to Update GeoIP Country database in each WebServer Jail defined by $TDIRS
# -------------------------------------------------------------------------
# Copyright (c) 2007 Vivek Gite 
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
GEOUPDATE=/usr/local/bin/geoipupdate
GEODB=/usr/local/share/GeoIP/GeoIP.dat
# ------------------
# TRUE = Update in Jail
# FALSE = Update only at $GEODB
CHROOTED=FALSE
# ------------------
# DIR:user:group format, only used if CHROOTED == TRUE
TDIRS="/webroot/apache/usr/local/geoip|www:www /webroot/nginx/usr/local/geoip|nginx:nginx"
CHOWN=/bin/chown
CP=/bin/cp
[ -f $GEOUPDATE ] && $GEOUPDATE
# Update if chrooted Apache jail...
if [ "$CHROOTED" == "TRUE" ]
then
 for i in $TDIRS
 do
	d=$(echo "$i" | cut -d'|' -f1)
	p=$(echo "$i" | cut -d'|' -f2)
	$CP -f $GEODB $d
	$CHOWN $p $d/$(basename $GEODB)
 done
fi
{ 4 comments… add one }
  • Mould Maker April 27, 2011, 2:27 am

    So, how to get the License Key & Product Id ?

    • Vivek Gite April 6, 2012, 6:09 pm

      You can order it from the maxmind site only.

  • Juan Giordana February 19, 2010, 4:01 pm

    There’s a typo on the first nginx (nginix).

    • Vivek Gite April 6, 2012, 6:09 pm

      Thanks for the heads up!

Security: Are you a robot or human?

Leave a Comment