<?xml version="1.0" encoding="UTF-8"?>
<posts to="2010-03-26T21:47:26+00:00" from="2010-03-26T21:47:26+00:00"><post><id>48</id><rid>55</rid><title>Keeping the GeoIP databases up to date</title><section>Server Admin</section><author><username>thebluerhino.myopenid.com</username><name>Andrew Milsted</name></author><content><![CDATA[I needed to keep my GeoIP db up to date for my stats package so I decided to write a cron script that would do it for me.

[code=bash]#!/bin/bash

#############################################################
# ./geoipupdate = Auto updates the free GeoIP databases
# (c) andrew[at]bluerhinos.co.uk 2010 : Creative Commons
#############################################################

#list of urls
URLS=" http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz"
URLS="$URLS http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"

#target directory
TARGETDIR="/var/lib/GeoIP"

for URL in $URLS
do
        wget -q -N -P "$TARGETDIR" "$URL"
        BASENAME=`basename "$URL"`
        gunzip -f  "$TARGETDIR/$BASENAME";
done
[/code]

Place the above code (or download here http://blogs.bluerhinos.co.uk/data/files/9/geoipupdate ) into /etc/cron.monthly/geoipupdate

Note: they update their db on the 1st or 2nd so I changed my /etc/crontab so that the monthly scrips run on the 3rd]]></content><html><![CDATA[<b>Code Tags:</b> bash<br />
I needed to keep my GeoIP db up to date for my stats package so I decided to write a cron script that would do it for me.<br style="clear:left;"/><br style="clear:left;"/><pre class="bash" style="color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0; padding:5px;"><div style="font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; border-bottom: 1px solid #d0d0d0; padding: 0px;">bash code:</div><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #666666; font-style: italic;">#############################################################</span><br style="clear:left;"/><span style="color: #666666; font-style: italic;"># ./geoipupdate = Auto updates the free GeoIP databases</span><br style="clear:left;"/><span style="color: #666666; font-style: italic;"># (c) andrew[at]bluerhinos.co.uk 2010 : Creative Commons</span><br style="clear:left;"/><span style="color: #666666; font-style: italic;">#############################################################</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #666666; font-style: italic;">#list of urls</span><br style="clear:left;"/><span style="color: #007800;">URLS=</span><span style="color: #ff0000;">&quot; <a href="http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz&quot;">http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz&quot;</a></span><br style="clear:left;"/><span style="color: #007800;">URLS=</span><span style="color: #ff0000;">&quot;$URLS <a href="http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz&quot;">http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz&quot;</a></span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #666666; font-style: italic;">#target directory</span><br style="clear:left;"/><span style="color: #007800;">TARGETDIR=</span><span style="color: #ff0000;">&quot;/var/lib/GeoIP&quot;</span><br style="clear:left;"/>&nbsp;<br style="clear:left;"/><span style="color: #000000; font-weight: bold;">for</span> URL <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$URLS</span><br style="clear:left;"/><span style="color: #000000; font-weight: bold;">do</span><br style="clear:left;"/>        <span style="color: #c20cb9; font-weight: bold;">wget</span> -q -N -P <span style="color: #ff0000;">&quot;$TARGETDIR&quot;</span> <span style="color: #ff0000;">&quot;$URL&quot;</span><br style="clear:left;"/>        <span style="color: #007800;">BASENAME=</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #ff0000;">&quot;$URL&quot;</span><span style="color: #000000; font-weight: bold;">`</span><br style="clear:left;"/>        <span style="color: #c20cb9; font-weight: bold;">gunzip</span> -f  <span style="color: #ff0000;">&quot;$TARGETDIR/$BASENAME&quot;</span>;<br style="clear:left;"/><span style="color: #000000; font-weight: bold;">done</span><br style="clear:left;"/>&nbsp;</pre><br style="clear:left;"/><br style="clear:left;"/>Place the above code (or download here <a href="http://blogs.bluerhinos.co.uk/data/files/9/geoipupdate">http://blogs.bluerhinos.co.uk/data/files/9/geoipupdate</a> ) into /etc/cron.monthly/geoipupdate<br style="clear:left;"/><br style="clear:left;"/>Note: they update their db on the 1st or 2nd so I changed my /etc/crontab so that the monthly scrips run on the 3rd<div class="postTools"></div>

]]></html><datestamp>2010-03-26T21:47:26+00:00</datestamp><timestamp>2010-03-26T21:57:35+00:00</timestamp><blog>8</blog><key>3642623819d780f910818c9b431c6dc5</key><metadata><code_tags>bash</code_tags></metadata><attached_data><data>http://blogs.bluerhinos.co.uk/data/10.xml</data></attached_data><links><uri>http://blogs.bluerhinos.co.uk/uri/10</uri><permalink>http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.html</permalink></links><formats><format type="text/html">http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.html</format><format type="text/xml">http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.xml</format><format type="image/png">http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.png</format></formats><revisions><revision>http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.xml?revision=48</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.xml?revision=49</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.xml?revision=50</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.xml?revision=51</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.xml?revision=52</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.xml?revision=53</revision><revision>http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.xml?revision=54</revision><revision current="true">http://blogs.bluerhinos.co.uk/thinkblue/48/Keeping_the_GeoIP_databases_up_to_date.xml?revision=55</revision></revisions><comments/></post></posts>

