Create a gist now

Instantly share code, notes, and snippets.

@hwdsl2 /GeoIP_update.sh Secret
Last active Sep 30, 2015

What would you like to do?
IPTables GeoIP database monthly update script and cron job
#!/bin/bash
# /root/GeoIP_update.sh
ls /opt/src/xtables-addons-* >/dev/null 2>&1
[ $? -ne 0 ] && { echo "Error: xtables-addons source folder not found."; exit 1; }
cd /opt/src/xtables-addons-*
cd geoip
./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; }
./xt_geoip_build GeoIPCountryWhois.csv
mkdir -p /usr/share/xt_geoip/
cp -rf {BE,LE} /usr/share/xt_geoip/
# /etc/cron.d/update_GeoIP
# Global variables
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
MAILTO=root
HOME=/
25 4 5,10 * * root /root/GeoIP_update.sh >/dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment