Best approach to edit linux configuration file

H

Himanshu Garg

I have to setup the DNS server. For this I have to edit the configuration files.

For this I have to search if the lines(block of text) already exist in the file and if not, I have to add them to the file.

So, I want to know what is the best way to accomplish this.
 
C

Chris Angelico

I have to setup the DNS server. For this I have to edit the configuration files.

For this I have to search if the lines(block of text) already exist in the file and if not, I have to add them to the file.

So, I want to know what is the best way to accomplish this.

Is your script allowed to take complete control of the file, or do you
have to cope with human edits?

If you CAN take control, things are easy. Just keep track of your own
content and match exact lines; as long as you always make consistent
output, you can look for those lines precisely.

But if, as I suspect from your (scanty) description, you can't, then
you'll need to figure out how to identify whether the lines exist or
not. That means text parsing rules. Python can definitely do this;
it's simply a matter of figuring out what you're looking for, what
you're adding, etc.

Configuring DNS is pretty easy for a script to do. I've done it
several times (though only once in Python - other languages other
times).

ChrisA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top