Hello oh wise ones

I am sure that this has been done a million times before, however I can't seem to find it by searching here or googling. I have a situation where I have 3 DNS servers running BIND9 and a total of 18 zone files all in /var/named/zone. In the event of a failure I need to be able to do the following:

1. Stop named on the Primary DNS server (Already solved/written).

2. Globally find and replace all instances of the first 3 octets of an IP address with a different 3, for exaple: 192.168.10.x with 10.2.5.x leaving the last octet in place. I have partially done this and tested and although dirty it works:

`perl -pi -e 's/192.168.10/10.2.5/g' $ROOT_DIR/*`;

Open to a suggestion for a cleaner way to do that within the script.

3. This one is what is giving me the real issue. I need to be able to change serial numbers in all of the 18 zone files so the slaves will update properly. I can do it in a fairly dirty method one file at a time using this:

my $zonefile = DNS::ZoneParse->new("$ROOT_DIR/zone.com", $origin);
print "Changing $zonefile serial number\n";
$zonefile->new_serial();
open NEWZONE, ">$ROOT_DIR1/zone.com" or die "ERROR - $zonefile open failed";
print NEWZONE $zonefile->output();
close NEWZONE;

However I find I have issue with it as it blows away my $ORIGIN and CNAME lines.

Would like to find a simpler solution to read in the entire directory (it's all zone files btw) put them into a list and then do an edit on each maybe something along these lines(beware I know my syntax is lacking here and thus my request for help):

opendir $ROOT_DIR, ".";
@contents = grep !/^\.\.?$/, readdir $ROOT_DIR;
while (<>) {

?????

Here is the part I need help with, either being able to continue to use the DNS::ZoneParse Module and not have it clobber my $ORIGIN and CNAME lines or some other method of cleanly giving each file a new serial. Then of course:

} closedir ROOT_DIR;

4. Then finally restart the service (solved), send an email letting staff know this was run and what mode it is now in (partially solved), log the entire happenings within the script to a file for debug and time stamping. I have looked at a couple of things but seems there has to be an easy way to dump all out to a log like in shell script.(clueless).

Of course there are other admin things in the background, making backups of files and moving them around, etc., but have that solved as well.

Any direction you can provide would be enormously appreciated. Thanks to all in advance. Any questions do not hesitate.

Thanks -
Brad Jensen


In reply to DNS Failover by bjensen34

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.