[rbldnsd] Slightly OT: script to add to rbldnsd zone

Michael Tokarev mjt at tls.msk.ru
Fri Jan 28 23:52:27 MSK 2005


David Landgren wrote:
> Robin Lynn Frank wrote:
> 
>> I've been adapting a shell script we've been using to add such things as
>> dictionary spam, unauthorized relay attempts, hits on spamtraps, etc to
>> a postfix access map, so it can be used to add to a rbldnsd zone.
[]
>> cat /var/tmp/rbldnsd_abuse.map /var/tmp/rbldnsd_abuse.map
>> /var/lib/rbldns/abuse |\
>>    sort -f | uniq -i \
>>    > /var/tmp/rbldnsd_abuse.map
> 
> Something like:
> 
> (
>    echo ":127.0.0.4:DNSBL. Policy restrictions etc."
>    sort -f /var/tmp/rbldnsd_abuse
> ) | uniq -i > /var/tmp/rbldnsd_abuse.map
> 
> perhaps?

Please don't repeat the same mistake/bug, it is very important:
you should use atomic rename when everything is ready, and never
update the data file directly (except maybe in a few cases --
also questionable but sometimes possible -- when you want to add
a single line using >> shell construct).  Instead of
   command > datafile
use two-stage process:
   command > datafile.tmp && mv -f datafile.tmp datafile
This guarantees rbldnsd gets complete data file even if it will
try to load data while it is being constructed.

Uniq'ing entries isn't necessary - rbldnsd takes care of that
automatically.  When you got new entry to add, you may just add
it to the end of the file,
   echo $ip >> datafile
regardless whenever this entry already exists or not.  Ofcourse
it's a good idea to purge old entries from time to time an trim
the file by removing duplicates, in this case something like the
above command will do the trick.  Btw, my `sort' command does just
the right thing with the default : entry:
  $ echo -e '3\n:\n2\n1' | sort -f
  :
  1
  2
  3
Ie, it sorts : before all digits, so it becomes the first line as
it should... ;)  Also, my `sort' utility has -u option, a shortcut
for sort | uniq.

/mjt


More information about the rbldnsd mailing list