in reply to DNS Failover

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

You should escape the dots . in your regex: s/192\.168\.10/10.2.5/g. Otherwise the . stands for any character, which is probably not what you want.

There is a different solution, that may clean up your process of rewriting the configuration files: you could store all the real data in a template file, and write a placeholder instead of the parts that are changed on failover (i.e [%root_ip%].23 instead of 192.168.10.23 or 10.2.5.23).

Then every time you'd normally change the config files directly you now modify only the templates.

And you need a script that processes the templates, and substitutes the variables based on whether you're in failover mode or normal operation.

CPAN has many templating modules ready for you, like Template and Text::Template.

Replies are listed 'Best First'.
Re^2: DNS Failover
by bjensen34 (Initiate) on Oct 29, 2007 at 22:37 UTC
    Thanks for the first one, missed that

    Thank you also for the suggestion on using templates. I have followed the links and done some reading and find myself a bit confused.

    Would you not then have to maintain not only 18 zone files but 18 templates as well?? So if I added another 20 A records to each of the 18 zones I would in effect have to edit 18 files x2?

    As far as the script goes I am still faced with the same logic problem I believe as well in that I still need to figure out within the script which is doing other things how to pull up each templ file and pass the variables and still output new zone files?

    Perhaps I am not seeing the forest through the trees on this one. If you can help guide me a bit I would greatly appreciate it.

    Thanks -

    Brad Jensen

      Would you not then have to maintain not only 18 zone files but 18 templates as well?

      No, you wouldn't. You'd just maintain the templates, and generate the "real" config files automatically.

      Introducing Templates is effectively changing your problem from "read the config files, search and replace in them, and write them back" to "Fill the templates with variables, and write the output into the config files".

      If that confuses you, your best bet is to stay with your original solution, and wait until somebody has a better suggestion on how to handle it ;-)

        Ok believe I am following you now. So the 20 A Records get added to the templates only and then the script that calls the templates would generate new zone files.

        Sorry for the confusion. I will do a bit more digging on templates. Seems like it may very well be the best way to go.

        Thank you!

        Brad Jensen