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/ (cron job)

# 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 for more information.
# -------------------------------------------------------------------------
# ------------------
# TRUE = Update in Jail
# FALSE = Update only at $GEODB
# ------------------
# DIR:user:group format, only used if CHROOTED == TRUE
TDIRS="/webroot/apache/usr/local/geoip|www:www /webroot/nginx/usr/local/geoip|nginx:nginx"
# Update if chrooted Apache jail...
if [ "$CHROOTED" == "TRUE" ]
 for i in $TDIRS
	d=$(echo "$i" | cut -d'|' -f1)
	p=$(echo "$i" | cut -d'|' -f2)
	$CP -f $GEODB $d
	$CHOWN $p $d/$(basename $GEODB)	
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics via:

Category List of Unix and Linux commands
Disk space analyzers df duf ncdu pydf
File Management cat cp mkdir tree
Firewall Alpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilities bat exa
Network Utilities NetHogs dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searching ag grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN Alpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Juan Giordana Feb 19, 2010 @ 16:01

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

  • Mould Maker Apr 27, 2011 @ 2:27

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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum