GeoIP.dat Updater
05-24-2010 @ 5:23AM EDT
This is a bash script that will automatically download the latest GeoIP data file, uncompress it, and overwrite your old one each month. If you are not using mod_geoip then there's no need to run this.
How to use:
If you don't already have a mydir folder then create one (mkdir /mydir). Then copy and paste the code into a new geoipup.sh file in the /mydir folder (vi /mydir/geoipup.sh). Don't forget to set your permissions to make the file executable (chmod 0771 /mydir/geoipup.sh). Now you can copy and paste the following line into your crontab (type crontab -e after you SSH into your server):
59 23 2 * * /mydir/geoipup.sh
The above line will run the script at 11:59PM on the 2nd day of every month.
You can adjust the time but this normally takes a few seconds to run so there is little to no impact on your CPU load and the data file is normally not available until later in the evening. To be as up-to-date as possible with your data file, you can set the time to 0 */6 2 * * so that it will run the script every 6 hours on the 2nd day of the month to minimize the window of having an "outdated" data file (I've never seen an impact from using the old data file for a few hours).
A breakdown of this script:
#!/bin/bash <- Tells the server to run this script with the BASH interpreter.
cd /root/ <- Changes your directory to the /root directory.
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz <- Downloads the new data file.
gunzip GeoIP.dat.gz <- Extracts the new data file.
mv GeoIP.dat /GeoIP.dat <- Moves it to the root (/) directory (this may need to be changed based on where you configure your data file in httpd.conf).
Code:
#!/bin/bash
cd /root/
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz
mv GeoIP.dat /GeoIP.dat
cd /root/
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz
mv GeoIP.dat /GeoIP.dat
servers, linux, tutorials, scripts, geoip
Comments
This article hasn't been commented yet.


Write a comment
* = required field