hello,
In this situation you usually need to analyse the syntax of 'named.conf'.It is 
maybe a hard work based on the complexity of your file.Here,you can match the 
begin of 'view external {' block and add the additional lines from that 
location.I would do the modification as following:


my $cfgFile = "/etc/named.conf";

open (HD,$cfgFile) or die "$!";
my @config = <HD>;
close HD;

open (NAMEDCONF,">",$cfgFile) or die "$!";
for (@config)
{
    print NAMEDCONF $_;
    if (/view external \{/)
    {
        print NAMEDCONF "zone \"", $zone, "\" {\n";
        print NAMEDCONF "\ttype master;\n";
        print NAMEDCONF "\tfile \"", "hosts.$zone", "\";\n";
        print NAMEDCONF "};\n";
    }
}
close NAMEDCONF;


Hope that helps.



-----Original Message-----
>From: bsd <[EMAIL PROTECTED]>
>Sent: Feb 8, 2006 7:14 PM
>To: Liste Perl <beginners@perl.org>
>Subject: Inserting data inside {};  --> aka "script to update named.conf 
>handling zone"
>
>Hello,
>
>
>I am trying to use a modified version of the script produced by  
>cricket Liu (DNS & BIND Cookbook) :
>
>> # more addzone.pl
>> #!/usr/bin/perl -w
>>
>> $namedconf = "/etc/named.conf";
>>
>> die "Usage: $0 <zone> <template zone data file>\n" unless (@ARGV ==  
>> 2);
>> $zone = $ARGV[0];
>> $datafile = $ARGV[1];
>>
>> die "$namedconf must exist" unless (-r $namedconf);
>>
>> open(NAMEDCONF, ">>$namedconf") || die "Couldn't open $namedconf";
>>
>> open(TEMPFILE, "$datafile") || die "Couldn't open $datafile";
>>
>> open(DATAFILE, ">hosts.$zone") || die "Couldn't open hosts.$zone";
>> @temp = <TEMPFILE>;
>> print DATAFILE @temp;
>> close(DATAFILE);
>> close(TEMPFILE);
>>
>> print NAMEDCONF "zone \"", $zone, "\" {\n";
>> print NAMEDCONF "\ttype master;\n";
>> print NAMEDCONF "\tfile \"", "hosts.$zone", "\";\n";
>> print NAMEDCONF "};\n";
>>
>> close(NAMEDCONF);
>>
>> system("rndc reconfig") && die "Couldn't reconfig name server";
>>
>
>
>A version that will allow me to place the output of the printed  
>statement (NAMEDCONF) inside the statement :
>
>> view external {
>>
>> zone "141.15.165.in-addr.arpa" {
>>         type master;
>>         file "hosts.141.15.165.in-addr.arpa";
>> };
>>
>> zone "bout.com" {
>>         type slave;
>>         masters  { 19.3.12.2 ; };
>>         file "hosts.bout.com";
>> };
>>
>> ...
>>
>>
>> };
>
>
>For the moment when I execute the script, my NAMEDCONF statments ends  
>outside of the last "};" and I need It inside (because of zone  
>handling matter.
>
>I am a real beginner so any clue will be welcome.
>
>
>Thanks a lot --
>
>
>
>________________________________________________
>?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ
>¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
>Gregober ---> PGP ID --> 0x1BA3C2FD
>bsd @at@ todoo.biz
>________________________________________________
>?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ
>¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
>
>
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
><http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>


--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to