Skip to content

Instantly share code, notes, and snippets.

@datiti
Created May 13, 2015 10:14
Show Gist options
  • Save datiti/b3825ec7cec002eec089 to your computer and use it in GitHub Desktop.
Save datiti/b3825ec7cec002eec089 to your computer and use it in GitHub Desktop.
Update GeoIP database for xtables geoip module of iptables
#!/bin/bash
# /usr/local/sbin/GeoIP_update
#
# Update geoip databases for xtables geoip module of iptables
# Last updated: 20150513
#
XTABLESADDONS=/usr/lib/xtables-addons/
XTABLEGEOIPDIR=/usr/share/xt_geoip/
# the temporary directory to store geoip database
GEOIPDBDIR=/somedirectory
# goto geoip dir and download databases
cd ${GEOIPDBIR}
${XTABLESADDONS}/xt_geoip_dl
[ ! -f "./GeoIPCountryWhois.csv" ] && { echo "Error: GeoIPCountryWhois.csv file not found."; exit 1; }
[ ! -s "./GeoIPCountryWhois.csv" ] && { echo "Error: GeoIPCountryWhois.csv file is empty."; exit 1; }
# update xtables geoip databases
mkdir -p ${XTABLEGEOIPDIR}
${XTABLESADDONS}/xt_geoip_build -D ${XTABLEGEOIPDIR} GeoIPCountryWhois.csv
# /etc/cron.d/update_GeoIP
# Global variables
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
MAILTO=you@yourdomain.com
HOME=/root
# To be executed as root at 4:25am each 5th and 10th day of month
25 4 5,10 * * root /usr/local/sbin/GeoIP_update
#25 4 5,10 * * root /usr/local/sbin/GeoIP_update >/dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment