> Hi all,

Howdy,

> 
> In comp.unix.shell Alan Murrell posted this clever sed 
> solution for removing 
> entries from his named.conf file using only the domain name):
> 
> sed '/zone "domain.com" {/,/};/d' /etc/named.conf > newfile
> 
> Instead of using actual line numbers for the range of lines 
> (such as "1,4") 
> he uses two regexes that match to them.
> 
> How might one do this in Perl? Read in the whole file and then do a 
> multi-line substitution? 
> 
> Or a 'bigger' solution would be to read the lines one at a 
> time into a hash 
> structure ($domain{domain.com} for ex.), starting a new hash 
> key each time 
> one matches /^\s*zone.*/ ? This would then let one sort, do 
> whatever, and 
> write out the entire file afterwards in proper format.
> 
> No solution needed, just wondering about approaches (small and large).

Well, assuming your conf file isn't too huge, IE the size you could use File::Slurp on.

use File::Slurp;
my %named_conf = parse_conf(read_file("/etc/namedb/named.conf"));

Now parse_conf() takes the array that read_file() returned, and similar to what you 
said:

At a 'zone' file get domain then until it gets the };
It adds each attribute as a key and it's value as a value.

So you end up with a hash like this:

$named_conf{'domain.com'} => type => 'master',
                                     file => '/etc/named/master/domain.zone';
$named_conf{'domain2.net'} => type => 'slave',
                                        file => '...',
                                        masters => '1.1.1.1;2.2.2.2;
 
Or something like that, the syntax may be bad since I'm busy but that's the idea.

Although you said you simply want to remove a zone entry som that may be overkill now 
that I remmebere that.

How about :

 perl -e "use File::Slurp; $n = read_file('/etc/named.conf');$n =~ s/zone 
\"removeme.com\".*\}\;//" 

HTH

Dmuey

> -K
> 
> __DATA__
> zone "domain.com" {
>     type master;
>     file "domain.com";
> };
> zone "domain2.com" {
>     type master;
>     file "domain2.com";
> };
> ##

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to