LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-22-2007, 01:39 AM   #1
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Rep: Reputation: 30
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
 
Old 12-22-2007, 02:10 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
how does one of your bind zone files look like
and when converted to tinydns format, how does it look like?
 
Old 12-22-2007, 10:28 AM   #3
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Original Poster
Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with wild card syntax to semi-automate file conversion using a perl script kmkocot Linux - Newbie 5 12-12-2007 01:55 PM
How to share a ZFS file system between a global zone and a non global zone? crisostomo_enrico Solaris / OpenSolaris 7 11-28-2007 08:20 AM
finding out which time zone a person is in from a PHP script microsoft/linux Programming 7 03-01-2007 05:52 PM
[Perl] basic byte conversion script noir911 Programming 1 11-21-2006 01:01 AM
Perl file conversion results in a truncated file kshaffer Programming 0 01-31-2005 02:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration