in reply to Reading and *writing* configuration files

There is BIND::Conf_Parser which is a base class for parsing 8.x named.conf files. In a nutshell to retain bits of an existing conf file you first need to parse it so you can find the bits you want to keep, change the bits you want to change, then put Humpty Dumpty back together again....

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

  • Comment on Re: Reading and *writing* configuration files

Replies are listed 'Best First'.
Re: Re: Reading and *writing* configuration files
by DeathBunny (Sexton) on Apr 09, 2002 at 15:11 UTC
    I've looked at Bind::Conf, but it only reads named.conf files, it doesn't write them. :-(

      Ah that's kinda the idea. You read in the current file and parse it using a parser module. *You* make your changes to this parsed data set. *You* print out the new file from your munged data set.

      One significant problem with retaining comments is that they are only useful if the are relevant. Comments that relate to parts of the file which have been changed are worse than useless.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        <sarcasm>No kidding?</sarcasm> That's *kinda* what I'm looking for help with. Parsing the named.conf file was easy enough and, as you mentioned, I could have used Bind::Conf as a starting point for that.

        What I'm looking for is tip on writing a new, updated, config file back out.

        Maybe some more information would help. I'm currently writing a fresh new config (with no comments or formatting etc preserved from the original) to a temp file. Then I copy the old file to a .bak extension and copy the temp file over the /etc/named.conf file.

        So far so good. But I posted this query in the hopes that with all the massive knowledge and experience that the combined readers of PerlMonks have, that someone will have either tips on ways to improve this procedure or warning about things I might be doing badly.

        Maybe I should have been more clear in my initial post. Still, there have been some pretty good suggestions posted here and I definately feel more confident of what direction I should go in.