MAVERICK
asked on
Extracting data from zone files
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/z ones16/5/m averick.tl d
;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
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
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/z
;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
What addresses you need in that file ???
ASKER
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
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
man paste ;-)
ASKER
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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Running any of your greps over the sample zone file you supplied will return nothing. What is the actual data you're working with.
ASKER
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.c om
The expected result in the output should be;
discountersplus.com 216.240.151.84 ns4.ddwarehouse.com.
Thanks alot
Maverick
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.
;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.
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.c
The expected result in the output should be;
discountersplus.com 216.240.151.84 ns4.ddwarehouse.com.
Thanks alot
Maverick
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.
Anyway, give it a try and see what happens.
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
Do you have excel for UNIX?
Cool!!!
Cool!!!
ASKER
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.
:)
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.
:)