Re: Find a line, and comment out the next 5 lines

From: mdh (stratfan_at_mindspring.com)
Date: 04/20/04


Date: 19 Apr 2004 21:24:23 -0700

After providing you the obligatory warning about automating anything
to do with DNS (smile), what you're basically try to accomplish is the
following steps:

 1) examine a multiline string for the following pattern:

     \nzone "YOURTARGETZONE" {\n(arbitrary characters)\n(arbitrary
characters)\n(arbitrary characters);\n(arbitrary characters)}\n

 2) take the string (the entire file) and chop it into three parts:
       $prematch -- the characters before the match
       $thematch -- the characters matching the pattern
       $postmatch - the characters after the match

3) on $thematch, use the substitution operator to replace the
   newlines with "\n//"

4) join $prematch, $thematch, and $postmatch back into one string

5) write the result joined string back out as your new zone file

Try the following code snippet...

mdh

#!/usr/bin/perl

my $UID = "joeblow\@somecompany.com";
my $datestring = `date -u "+%m/%d/%Y %H:%M:%S"`;
$datestring =~ tr/\n\r//d; # delete trailing newline or carriage
return
my $targetdomain = "mydomain.com";
# define a variable using the HERE construct for simulated zone file
input..
my $sampleinput = <<"EOF";

zone "dontchangethisdomain.com" {
   type master;
   file "/somepath/to/dontchangethisdomain.com";
   notify yes;
 }

 zone "mydomain.com" {
    type master;
    file "/path/to/zone/mydomain.com";
    notify yes;
}

zone "leavethisalonetoo.com" {
   type master;
   file "/other/path/to/leavethisalonetoo.com";
   notify yes;
   }

EOF

my $prematch;
my $thematch;
my $postmatch;

# use a regular expression with "non-greedy" matching to the token
# "zone" and the closing brace character (}) to anchor on the zone
# definition matching the domain you want to comment out -- you
# want "non-greedy" matching cuz you want the shortest string that
# starts with "zone", has your target, and ends with a closing
# brace -- if you use a greedy match (.*), you'll match on the last
# brace in the file, commenting out multiple domains in error

if ($sampleinput =~ m/\n(.?)zone "$targetdomain"
\{\n(.*)type(.*);\n(.*)file(.*);\n(.*)notify(.*);\n(.?)\}/is) {
   $prematch = $`;
   $thematch = $&;
   $postmatch = $';
   $thematch =~ s/\n/\n\/\//g; # globally replace newlines with
newline and //
   print "$prematch\n";
   print "//domain taken out of named.conf at request of Customer by
$UID, $datestring";
   print "$thematch";
   print "$postmatch\n";
   }

exit;



Relevant Pages

  • Re: Thoughts on a large-scale DNS server...
    ... are zone file configurations the same. ... As for TTL, we currently use a 24 hour TTL, for zone file itself we then ... > sounds like a very conservative setup, and for DNS that's good. ...
    (freebsd-isp)
  • RE: Nameserver
    ... The local zone and the zone for my ... requests without using your ISP's name server. ... > work if the host entry in the zone file has a dynamic IP (not ... would be to enable DDNS. ...
    (RedHat)
  • Re: Zones disappearing
    ... entries under MicrosoftDNS that referred to the zone. ... DNS will override by design the primary zone file, ... disappearing. ... If the zone file already exists there is a second option for using an ...
    (microsoft.public.windows.server.dns)
  • Re: Subdomain novice issue
    ... >I have included the following in my main mydomain.com zone: ... If you have NS records for the subdomain, ... it doesn't really need to be a separate zone. ... record and just put the MX record in the mydomain.com zone file. ...
    (comp.unix.admin)
  • Re: The DNS server could not find or open zone file dns
    ... The DNS server could not find or open zone file ... Verify that the zone file is located in this directory and that it ... on the network all MS 2002 standard outlook clients are getting ...
    (microsoft.public.win2000.dns)