Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Extracting data from zone files

Posted on 2004-08-09
14
561 Views
Last Modified: 2010-04-21
I'm looking for a solution to the following problem...
I need a 3 column file of the domains like this
mydomain1.tld 10.0.0.85 ns1.mywebserver.tld.
mydomain2.tld 10.0.0.85 ns1.mywebserver.tld.
mydomain3.tld 10.0.0.86 ns1.myotherserver.tld.

I'm  in  the named zone root directory & grep returns a list of zone files like this..
#grep -lr 'SOA' *
zones5/12/experts-exchange.com
zones4/11/mydomain1.tld
zones4/15/mydomain2.tld

I can get the data into individual lists but not combined...
eg the domain names using..
# grep -r 'SOA' *|grep 'zones'|cut -d ':' -f 1|cut -d '/' -f 3
the dns server..
# cat `grep -r 'SOA' *|grep 'zones'|cut -d ':' -f 1`|grep '*'|awk '{print $5}
the IP of the website
cat `grep -r 'SOA' *|grep 'zones'|cut -d ':' -f 1`|grep 'SOA'|awk '{print $4}'

Here is a sample zone file
# cat /hsphere/local/var/named/zones16/5/maverick.tld
;BIND DUMP V8
$ORIGIN tld.
maverick   86400   IN      NS      ns2.myserver.tld.    ;Cl=3
        86400   IN      NS      ns1.myserver.tld.    ;Cl=3
        86400   IN      SOA     ns2.myserver.tld. nocadmin.myserver.tld. (
                2003123101 10800 3600 604800 86400 )    ;Cl=3
        86400   IN      A       10.0.0.84  ;Cl=3
        86400   IN      MX      10 pop3.maverick.tld.        ;Cl=3
$ORIGIN maverick.tld.
mail    86400   IN      CNAME  10  maverick.tld.   ;Cl=3
*       86400   IN      A       10.0.0.84  ;Cl=3

Thanks everyone
MAVERICK
0
Comment
Question by:MAVERICK
  • 5
  • 3
  • 2
  • +2
14 Comments
 
LVL 62

Expert Comment

by:gheist
ID: 11756212
What addresses you need in that file ???
0
 
LVL 1

Author Comment

by:MAVERICK
ID: 11756319
I need the 3 columns

If you mean IP Address - Assume first A record of the file.
 86400   IN      A       10.0.0.84  ;Cl=3

The hostname from the zone filename is fine.

Thanks
-John
0
 
LVL 20

Expert Comment

by:tfewster
ID: 11756418
man paste ;-)
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:MAVERICK
ID: 11756674
Close but no cigar ;-)

The main problem is that there is a chance the IPs/DNS wont line up with the hostnames

I tried doing it manually in excel and it didn't work out.

Thanks alot
Maverick
0
 
LVL 20

Assisted Solution

by:tfewster
tfewster earned 100 total points
ID: 11756683
Or if you don't like that:

#!/usr/bin/ksh
# zone.ksh  - Or whatever you call it, remember to exclude it from the list...

for ZONE in `grep -r 'SOA' * | grep -v zone.ksh|grep 'zones'|cut -d ':' -f 1`
do
  DNS=`echo $ZONE |cut -d '/' -f 3 `            # Or DNS=`basename $ZONE`
  IP=`grep '*' $ZONE|awk '{print $5}'`
  DOMAIN=`grep 'SOA' $ZONE|awk '{print $4}'`
  echo $DNS $IP $DOMAIN
done
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11757463
your examples do not match
could you please give a zone file and a example using this zone file to demonstrate what you expect as result

Also zone files can have a lot of different formats, with line breaks etc.
If you can guarantee that you onaly have *one* fixed format awk would do it, otherwise (several formats) start with doing it in perl
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11757495
Running any of your greps over the sample zone file you supplied will return nothing.  What is the actual data you're working with.
0
 
LVL 1

Author Comment

by:MAVERICK
ID: 11757866
tfewster: What is ksh?
ahoffmann: they are h-sphere autogenerated zone files - consistently the same

This is one of the actual zone files from the server;
[root@cp named]# cat zones15/5/discountersplus.com
;BIND DUMP V8
$ORIGIN com.
discountersplus 86400   IN      NS      ns4.ddwarehouse.com.    ;Cl=2
        86400   IN      NS      ns3.ddwarehouse.com.    ;Cl=2
        86400   IN      SOA     ns4.ddwarehouse.com. hostmaster.change-me-asap.com. (
                2003123101 10800 3600 604800 86400 )    ;Cl=2
        86400   IN      A       216.240.151.84  ;Cl=2
        86400   IN      MX      10 pop3.ddwarehouse.com.        ;Cl=2
$ORIGIN discountersplus.com.
mail    86400   IN      CNAME   pop3.ddwarehouse.com.   ;Cl=2
*       86400   IN      A       216.240.151.84  ;Cl=2

The zone15/5/discountersplus.com

The expected result in the output should be;
discountersplus.com 216.240.151.84 ns4.ddwarehouse.com.

Thanks alot
Maverick
0
 
LVL 20

Expert Comment

by:tfewster
ID: 11757994
Ksh=Korn shell, but that simple script should work under Bourne shell (sh) as well. It handles the case of e.g multiple SOA lines (tho' I have no idea if that's valid in a zone file) but line breaks could confuse it and you'd get a blank field in the output.

Anyway, give it a try and see what happens.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11758877
If the zone file is exactly as you have shown, it is impossible that any of your grep statements would have returned anything.  You've either mistyped the commands you are running, or you are using different data
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 11760951
awk 'BEGIN{ns="@";d="@"}($3=="SOA"){ns=$4;next}($1~"ORIGIN"&&ns!="@"){d=$2;next}($4=="A"){print d" "$5" "ns}' zone15/5/discountersplus.com

# to be improved in many ways, for example removing the trailing dot
0
 
LVL 1

Author Comment

by:MAVERICK
ID: 11765860
tfewster: your solution basically worked as intended.

The zone files do vary in structure slightly - Domains with subdomains were not processed correctly. The solution was to hand edit those in excel.

Thanks alot.
0
 
LVL 62

Expert Comment

by:gheist
ID: 11766710
Do you have excel for UNIX?
Cool!!!
0
 
LVL 1

Author Comment

by:MAVERICK
ID: 11766824
I copied the file onto my windows desktop PC for touchup and formatting.

I'm not sure how well the WINE libraries run under Unix, like such as FreeBSD. I'm curious that they make Excel for OS X, which is FreeBSD based.

:)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question