Parse "masters" ip from named.conf


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse "masters" ip from named.conf
# 1  
Old 04-15-2008
Parse "masters" ip from named.conf

Hi there, Im' trying to make a script to parse the BIND configuration file from my slave DNS server and obtain a certain parameter. The named.conf file has this format:
Code:
zone "0.170.20.10.in-addr.arpa" {
       type slave;
       file "0/./db.0.170.20.10.in-addr.arpa.bak";
       allow-notify { 172.16.1.208; };
       masters {
               172.16.1.208;
       };
};

zone "180.20.10.in-addr.arpa" {
       type slave;
       file "1/8/db.180.20.10.in-addr.arpa.bak";
       allow-notify { 172.16.1.208; };
       masters {
               172.16.1.208;
       };
};

zone "0.180.20.10.in-addr.arpa" {
       type slave;
       file "0/./db.0.180.20.10.in-addr.arpa.bak";
       allow-notify { 172.16.1.208; };
       masters {
               172.16.1.208;
       };
};

I want to parse, given a zone name, the IP addres in "masters { }" for that zone.
The closest I've got is
Code:
nawk '/zone "180.20.10.in-addr.arpa"/,/[000-999].[000-999].*;/' /opt/bind/etc/named.conf

but it stops in the "allow-notify" line. I can't use "};" regexp neigther because is also stops in the allow-notify.
Any idea will be welcome Smilie
# 2  
Old 04-15-2008
Quote:
Originally Posted by Citricut
I want to parse, given a zone name, the IP addres in "masters { }" for that zone.
The closest I've got is
Code:
nawk '/zone "180.20.10.in-addr.arpa"/,/[000-999].[000-999].*;/' /opt/bind/etc/named.conf

but it stops in the "allow-notify" line. I can't use "};" regexp neigther because is also stops in the allow-notify.
Any idea will be welcome Smilie
If the file always has the final "};" at start of line, you can match that.

Code:
nawk '/zone "180.20.10.in-addr.arpa"/,/^};/{ if ($0 !~ /[^ .0-9;]/) print }' /opt/bind/etc/named.conf

Trimming the trailing semicolon still left as an exercise.
# 3  
Old 04-15-2008
And thanks to era's help, here is the code!
Code:
 nawk '/zone "180.20.10.in-addr.arpa"/,/^};/{ if ($0 !~ /[^ .0-9;]/) print }' /opt/bind/etc/named.conf |sed 's/^[ \t]*//;s/\;//'

I wanted to parse this so I can have a record of wich was the masters IP in the moment I remove the zone from the named.conf file.

Thank you very much!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Solaris

Changing "rx_queue_number" in "ixgbe.conf". Reboot or Network Restart?

Hi all, First post here. Working on Solaris 10, on a Sun t4-4, need to change RX queue depth(ethernet, not HBA) and was wondering if i could get by with just restarting the network or if i should just bounce the whole shebang. Apologies if i missed a similar thread. if there is one, please... (2 Replies)
Discussion started by: caspnx
2 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Red Hat

How to delete a file named "~" ???

When i 'ls' the bin folder, there was "~" tilde in the list. How to delete this safely as this symbol represents home folder. Kindly help. (1 Reply)
Discussion started by: frozensmilz
1 Replies

5. UNIX for Advanced & Expert Users

separate "named daemon" message from /var/adm/messages

Hello group, How can I separate "named daemon" messages to the other file instead of /var/adm/messages. I still want all other daemons log the messages to /var/adm/messages. i.e. named => /var/adm/named.message other daemons => /var/adm/messages. I searched unix.com, and google but I still... (5 Replies)
Discussion started by: dannytrinh
5 Replies

6. UNIX for Advanced & Expert Users

The "PS" command was displaying*terminals named as "SYSCON"

Hi, When typing the command ps -fe.the system is showing a process called SYSCON:confused:.... I am not sure what process is that.I hava a script that kills all command staring with 'sys' but i don't want to kill syscon:( since i think it is some system process:confused: .Please help me to find... (1 Reply)
Discussion started by: kiranjose85
1 Replies

7. UNIX for Dummies Questions & Answers

Unix masters please help newbie on "find" command

please help me figure out how to do this I wont lie, this is for a homework problem and I have searched on google for a long time and still can't figure out what to do. here is the problem So there's a folder let's say called "bare" in it, there are 10 dirs with names from "part1" through... (2 Replies)
Discussion started by: white_raven0
2 Replies

8. UNIX for Dummies Questions & Answers

directory named "-filedir"

How do you delete a directory named -filedir? (2 Replies)
Discussion started by: jskillet
2 Replies

9. Solaris

Directory named "~" that points to root

I don't know how this got here, but in a directory on one of my servers I see a directory named ~ that points to root. Has anyone ever seen anything like this before. I'm affraid to delete it in case it wipes out everything on root. - HELP:eek: (1 Reply)
Discussion started by: jskillet
1 Replies
Login or Register to Ask a Question