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"
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
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.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
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.
> 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
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.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
To remove the "toxtracker.info" zone:
awk -v s=toxtracker.info 'BEGIN{RS=""; s="zone \""s"\""} $0~s{print $0"\n"}'
Justin
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
> 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