Skip to content

Instantly share code, notes, and snippets.

@hwdsl2
Last active September 30, 2015 20:26
Show Gist options
  • Save hwdsl2/fdc6f76a0bcd441cb933 to your computer and use it in GitHub Desktop.
Save hwdsl2/fdc6f76a0bcd441cb933 to your computer and use it in GitHub Desktop.
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