The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 09:52 PM
Unix masters please help newbie on "find" command white_raven0 UNIX for Dummies Questions & Answers 2 09-26-2005 09:54 PM
directory named "-filedir" jskillet UNIX for Dummies Questions & Answers 2 09-22-2004 04:25 PM
Directory named "~" that points to root jskillet SUN Solaris 1 08-06-2004 09:23 AM
better information source than "man rc.conf"? xyyz UNIX for Dummies Questions & Answers 1 03-01-2003 05:42 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 5
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-15-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,094
Quote:
Originally Posted by Citricut View Post
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
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.
Reply With Quote
  #3 (permalink)  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 5
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!
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0