LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   TinyDNS zone file conversion script (https://www.linuxquestions.org/questions/programming-9/tinydns-zone-file-conversion-script-608499/)

keysorsoze 12-22-2007 01:39 AM

TinyDNS zone file conversion script
 
Hi! I am working on modifying a pre-built script to convert all my zone files that are from bind into tinydns format. My zone files are in the current format mydomain.com.db and I need to dump it out into the tinydns data format. I have been trying to modify the following script with no luck. But I do know where the problem lies I think.


## Entire Script ##

#!/bin/bash
BINDTOTINYDNSPATH=/root/scripts/bind-to-tinydns
NAMEDPATH=/var/named

cd $BINDTOTINYDNSPATH
rm -f data-local
rm -f tmp/*
rm -f zones-named/*
rm -f zones/*

#Now we are going to create a script to copy the original bind zones-named/db files to $BINDTOTINYDNSPATH/zones-named
ls -1 $NAMEDPATH/*.db | awk '{print "cp "$1" zones-named/"}' > tmp/copy-bind-zones.sh

sh tmp/copy-bind-zones.sh #copy all bind zones/db files to $BINDTOTINYDNSPATH/zones-named
cd $BINDTOTINYDNSPATH/zones-named #change to $BINDTOTINYDNSPATH/zones-named

#create the conver-to-tinydns.sh script. This script will convert the bind zones/db files to tinyDNS data

ls -1 *.db | sed -e 's/db.//' | awk '{print "./bind-to-tinydns "$1" zones/data-"$1" tmp/data-"$1".tmp < zones-named/db."$1}' > ../tmp/convert-to-tinydns.sh

cd $BINDTOTINYDNSPATH #change to bind-to-tinydns path
sh tmp/convert-to-tinydns.sh # convert the bind zones/db files to tinyDNS data
cat zones/data* >> data-local #merge all tinyDNS zone data in one file

The main part of the problem is I believe this part of the script. I can't fully figure out what it does besides listing the contents and doing a sed replacement.


ls -1 *.db | sed -e 's/db.//' | awk '{print "./bind-to-tinydns "$1" zones/data-"$1" tmp/data-"$1".tmp < zones-named/db."$1}' > ../tmp/convert-to-tinydns.sh


When I run the script and got the following:

tmp/convert-to-tinydns.sh: line 64: zones-named/db.orbistelemedicine.org.db: No such file or directory
tmp/convert-to-tinydns.sh: line 65: zones-named/db.mydomain.org.tw.db: No such file or directory
tmp/convert-to-tinydns.sh: line 66: zones-named/db.mydomain.com.vn.db: No such file or directory
tmp/convert-to-tinydns.sh: line 67: zones-named/db.mydomain.com.db: No such file or directory
tmp/convert-to-tinydns.sh: line 68: zones-named/db.mydomain.org.db: No such file or directory
tmp/convert-to-tinydns.sh: line 69: zones-named/db.tsd.flightsafety.com.db: No such file or directory
tmp/convert-to-tinydns.sh: line 70: zones-named/db.mydomain.org.db: No such file or directory



Here are the contents of the "zone-named" directory


/root/scripts/bind-to-tinydns/zones-named
--r-- 1 root root 497 Dec 22 02:04 mydomain.org.tw.db
-r--r--r-- 1 root root 550 Dec 22 02:04 mydomain.org.vn.db
-r--r--r-- 1 root root 336 Dec 22 02:04 mydomain.org.db
-r--r--r-- 1 root root 456 Dec 22 02:04 mydomain.org.db
-r--r--r-- 1 root root 1.1K Dec 22 02:04 mydomain.com.db
-r--r--r-- 1 root root 431 Dec 22 02:04 mydomain.com.db
-r--r--r-- 1 root root 473 Dec 22 02:04 mydomain.org.db
-r--r--r-- 1 root root 345 Dec 22 02:04 mydomain.db
-r--r--r-- 1 root root 488 Dec 22 02:04 mydomain.org.db


I have tried to modify the problematic portion to:

ls -1 *.db | sed -e 's/db.//' | awk '{print "./bind-to-tinydns "$1" zones/data-"$1" tmp/data-"$1".tmp < zones-named/"$1}' > ../tmp/convert-to-tinydns.sh


To try to remove the .db leading but then I get the following errors when it runs:

tmp/convert-to-tinydns.sh: line 66: ./bind-to-tinydns: No such file or directory
tmp/convert-to-tinydns.sh: line 67: ./bind-to-tinydns: No such file or directory
tmp/convert-to-tinydns.sh: line 68: ./bind-to-tinydns: No such file or directory
tmp/convert-to-tinydns.sh: line 69: ./bind-to-tinydns: No such file or directory
tmp/convert-to-tinydns.sh: line 70: ./bind-to-tinydns: No such file or directory
tmp/convert-to-tinydns.sh: line 71: ./bind-to-tinydns: No such file or directory


I then tried:

ls -1 *.db | sed -e 's/db.//' | awk '{print "./bind-to-tinydns "$1" zones/data-"$1" tmp/data-"$1".tmp < zones-named/"$1"}' > ../tmp/convert-to-tinydns.sh

but got:

awk: {print "./bind-to-tinydns "$1" zones/data-"$1" tmp/data-"$1".tmp < zones-named/"$1"}
awk: ^ unterminated string
cat: zones/data*: No such file or directory


Can someone please point me on what I am doing wrong? I can't seem to remove the darn db. infront of db.mydomain.org.db to get plain mydomain.org.db.





Thanks

ghostdog74 12-22-2007 02:10 AM

how does one of your bind zone files look like
and when converted to tinydns format, how does it look like?

keysorsoze 12-22-2007 10:28 AM

Ghostdog:

Here is the format of my zone file when I run

bind-to-tinydns mydomain.org.db foo foo.tmp < mydomain.org.db

It converts fine, its just we have roughly 60 domains we are authoritative for and running this on 60 domains by hand is not pretty in terms of carpal tunnel setting in. That is the purpose of the script above, which is to take all our domains.com.db zone files and dump them out into tinydns format. We can then just "cat" all of them into one large file. But first I got to get the conversion part going which is the script above.



Zmydomain.org.db.:mydomain.org.:root.mydomain.org.:2007100200:3600:900:2592000:1800
&mydomain.org.db.::NS01.mydomain.COM.:86400
&mydomain.org.db.::NS02.mydomain.COM.:86400
@mydomain.org.db.::mailhost.mydomain.org.:10:86400
+mydomain.org.db.:208.97.97.89:86400
+localhost.mydomain.org.db.:127.0.0.1:86400
+mailhost.mydomain.org.db.:122.152.130.72:86400
+www.mydomain.org.db.:208.97.97.89:86400


All times are GMT -5. The time now is 04:59 PM.