Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Script to delete zone from named.conf

1,207 views
Skip to first unread message

bsd

unread,
Feb 4, 2010, 12:12:55 PM2/4/10
to bind-...@isc.org
Hello,

I am looking for a script to delete a zone from named.conf and maybe also from server (zone file).

My zone file looks like that (but could have some variations). Everything inside brackets should be deleted… and eventually the host file.

zone "abc.com" {
type slave;
masters { 213.14.17.2 ; };
file "hosts.abc.com";
};

zone "def.fr" {
type slave;
masters { 23.174.17.2 ; };
file "hosts.def.fr";
};

zone "xyz.net" {
type slave;
masters { 23.74.27.2 ; };
file "hosts.xyz.net";
};

I am not really a script guru and don't really know how to do that (sed ?).

Thanks for your support.

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Gregober ---> PGP ID --> 0x1BA3C2FD
bsd @at@ todoo.biz
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

P "Please consider your environmental responsibility before printing this e-mail"


Rick Dicaire

unread,
Feb 4, 2010, 12:22:52 PM2/4/10
to bsd, bind-...@isc.org
On Thu, Feb 4, 2010 at 12:12 PM, bsd <b...@todoo.biz> wrote:
> zone "abc.com" {
>       type slave;
>       masters  { 213.14.17.2 ; };
>       file "hosts.abc.com";
> };

You could put the whole statement on one line, then use grep or sed
based on the zone name.
Operationally, it'd work, and no doubt others will argue aesthetic
reasons not to do this. Alternately
a more complicated script could be written to handle the format as you
currently have it.

--
aRDy Music and Rick Dicaire present:
http://www.ardynet.com
http://www.ardynet.com:9000/ardymusic.ogg.m3u

bsd

unread,
Feb 4, 2010, 12:57:32 PM2/4/10
to Rick Dicaire, bind-...@isc.org
Thanks for your reply…

I know I can do that with grep, but you see I have 270 domains to delete from my named.conf.

My question was more: has anyone got a working script that I can use in order to delete name from my "named.conf" file ?


Idealy It should be a script that I can use in a "for do done" sequence like

for i in `cat list_to_delete.txt`
do my_remove_script.(sh|pl|xx) $i done


Thanks.

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Evan Hunt

unread,
Feb 4, 2010, 1:19:07 PM2/4/10
to bsd, bind-...@isc.org
> I know I can do that with grep, but you see I have 270 domains to delete
> from my named.conf.
>
> My question was more: has anyone got a working script that I can use in
> order to delete name from my "named.conf" file ?

cat named.conf | \
awk 'BEGIN {suppress = 0}
/zone "whatever.com"/ {suppress = 1}
{if (suppress == 0) print; if ($1 == "};" && NF == 1) suppress = 0}'

Or words to that effect. Works as long as the zones are always formatted
the same way.

--
Evan Hunt -- ea...@isc.org
Internet Systems Consortium, Inc.

James O'Gorman

unread,
Feb 4, 2010, 3:01:48 PM2/4/10
to bsd, bind-...@isc.org
On 4 Feb 2010, at 17:12, bsd wrote:

> Hello,
>
> I am looking for a script to delete a zone from named.conf and maybe also from server (zone file).
>
> My zone file looks like that (but could have some variations). Everything inside brackets should be deleted… and eventually the host file.

Assuming all zone statements are identically formatted (as per your examples), then the following will work:

sed -e '/^zone "bar.com" {$/,/^};$/ d' -i .bak named.conf

That looks for a line that is exactly "zone "..." {" and another that is exactly "};" - and then deletes those lines and everything in between.

If you want to create a script to do this, you could do:

#!/bin/sh

zone=$1
sed -e "/^zone \"$zone\" {/,/^};$/ d" -i .bak named.conf
rm $zone

James

bsd

unread,
Feb 4, 2010, 3:02:50 PM2/4/10
to Evan Hunt, bind-...@isc.org
Thanks Evan,

I'll try that and maybe try to embed that on a bash script…

The formatting should be the same for most of my domains… Anyway I'll test that on copy of my zone file ;-)

sed and awk haven't got so friendly syntax; but they are indeed very powerful…


Sincerly yours.

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Justin T Pryzby

unread,
Feb 4, 2010, 4:27:27 PM2/4/10
to bind-...@lists.isc.org
On Thu, Feb 04, 2010 at 06:19:07PM +0000, Evan Hunt wrote:
> > I know I can do that with grep, but you see I have 270 domains to delete
> > from my named.conf.
> >
> > My question was more: has anyone got a working script that I can use in
> > order to delete name from my "named.conf" file ?
>
> cat named.conf | \
> awk 'BEGIN {suppress = 0}
> /zone "whatever.com"/ {suppress = 1}
> {if (suppress == 0) print; if ($1 == "};" && NF == 1) suppress = 0}'
>
> Or words to that effect. Works as long as the zones are always formatted
> the same way.
As an alternative:

To remove the "toxtracker.info" zone:
awk -v s=toxtracker.info 'BEGIN{RS=""; s="zone \""s"\""} $0~s{print $0"\n"}'

Justin

Justin T Pryzby

unread,
Feb 4, 2010, 4:50:55 PM2/4/10
to bind-...@lists.isc.org
On Thu, Feb 04, 2010 at 02:27:27PM -0700, Justin T Pryzby wrote:
> awk -v s=toxtracker.info 'BEGIN{RS=""; s="zone \""s"\""} $0~s{print $0"\n"}'
Doh, should be:
awk -v s=toxtracker.info 'BEGIN{RS=""; s="zone \""s"\""} $0!~s{print $0"\n"}'

Mark Andrews

unread,
Feb 4, 2010, 5:16:03 PM2/4/10
to Justin T Pryzby, bind-...@lists.isc.org

In message <20100204212...@norchemlab.com>, Justin T Pryzby writes:
> On Thu, Feb 04, 2010 at 06:19:07PM +0000, Evan Hunt wrote:
> > > I know I can do that with grep, but you see I have 270 domains to delete
> > > from my named.conf.
> > >
> > > My question was more: has anyone got a working script that I can use in
> > > order to delete name from my "named.conf" file ?
> >
> > cat named.conf | \
> > awk 'BEGIN {suppress = 0}
> > /zone "whatever.com"/ {suppress = 1}
> > {if (suppress == 0) print; if ($1 == "};" && NF == 1) suppress = 0}'
> >
> > Or words to that effect. Works as long as the zones are always formatted
> > the same way.
> As an alternative:
>
> To remove the "toxtracker.info" zone:
> awk -v s=toxtracker.info 'BEGIN{RS=""; s="zone \""s"\""} $0~s{print $0"\n"}'
>
> Justin
> _______________________________________________
> bind-users mailing list
> bind-...@lists.isc.org
> https://lists.isc.org/mailman/listinfo/bind-users

Recent version of named-checkconf have a -p (print) option which
will emit named.conf, sans comments, in a consistent style which
will then be easy to post process.
--
Mark Andrews, ISC
1 Seymour St., Dundas Valley, NSW 2117, Australia
PHONE: +61 2 9871 4742 INTERNET: ma...@isc.org

Sam Wilson

unread,
Feb 5, 2010, 5:50:55 AM2/5/10
to comp-protoc...@isc.org
In article <mailman.365.1265321...@lists.isc.org>,
Mark Andrews <ma...@isc.org> wrote:

> Recent version of named-checkconf have a -p (print) option which
> will emit named.conf, sans comments, in a consistent style which
> will then be easy to post process.

Shame about the "sans comments" - easy comprehension or easy management
- take your pick. (Yes, I know it's a difficult task to preserve
commenting - BTDT.)

Sam

0 new messages