Thursday, July 30, 2009

Keeping your Geolocation up to date

If you host Open Ads or use Geographic targeting you will realise that from time to time you need to update you geo-location data file. This is an shell script to help

Script

#!/bin/sh
# retrieve and update Geolocation database

#get date...
today=`date +%d-%m-%y`
#today=`date +%d-%m-%y` #date in this format 04-08-09
#today=`date +%Y%m%%d` #date in this format 20090804

#go to folder
cd /home/adserver/

#grab data file
/usr/bin/wget -q --limit-rate=100k wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

# Check if file exists

if [ -f /home/adserver/GeoIP.dat.gz ]
then
#backup current file
if [ -f /home/adserver/GeoIPCity.dat ]
then
/bin/mv /home/adserver/GeoIP.dat /home/adserver/GeoIP-$today.dat
fi

#uncompress new file
/bin/gzip -d /home/adserver/GeoIP.dat.gz
fi

Cron Job
Let us say the file above is called update.sh. Add this to your cron.

0 2 7 * * /bin/sh /home/adserver/update.sh > dev/null 2>&1

Notes:

1. Ensure the full paths for mv, cd, wget are correct
you can find that by doing a whereis command name e.g whereis mv

2. Change "/home/adserver/" to the your path to where you want to put the file

3. if " if [ -f filename ] ..." does not work try "if[ -e filename ].."

4. The service is free, from maxmind.com so I try not to abuse their servers.
a) limit the download rate to --limit-rate=100k
b) update once month usually about the 5,6,7th ( the say the 1st of the month but the updates are usually late
( paid services are available)

5. you an remove the old file using "/bin/rm -f /home/adserver/GeoIP.dat " but I am one for backups


Useful

Audio Noise Removal

Many times in record clips we end up with unwanted background noise. Recently faced with the situation, I  needed to clean up some audio and...