Is there a program/script to modify .conf files?

4

3

I want to modify a file like /etc/gdm/custom.conf from the shell or a script.

# GDM configuration storage
[xdmcp]
[debug]
[daemon]
AutomaticLoginEnable=true;
AutomaticLogin=username;

But the idea is that I can add a line to a section and it check if the section is defined, (add the definition if not), the property is defined, let it undefine (erase the line), (and delete the section header if there is no property defined), etc...

I didn't find anything except gconftool-2 but it do not explain how to modify other files. (there is a shema file there).

eloyesp

Posted 2010-06-22T15:59:11.043

Reputation: 403

8conf files do not have a fixed markup of any kind. Compare f.e. the /etc/gdm/custom.conf to /etc/X11/xorg.conf or /etc/resolv.conf. – Bobby – 2010-06-22T17:22:17.603

as bobby states there is no such thing as .conf syntax but lots of scripting languages do have good config parser modules. you may achive what you are looking for with a short self written script. e.g. in python or perl – matthias krull – 2010-06-23T15:39:47.250

Answers

4

Augeas is a: A command line tool to manipulate configuration from the shell (and shell scripts). (among other things)

It uses lenses to transform every file to xml, give special tools to edit them, and use the lenses to write the file back in native format.

eloyesp

Posted 2010-06-22T15:59:11.043

Reputation: 403

This is exactly what I was looking for. Easy to install, easy to use. Just a note, this tool is in the default Ubuntu repos. – Matthew – 2011-12-13T03:45:32.117

And what you need is the desktop.aug module. – ℝaphink – 2012-05-09T21:35:55.517

0

Edit:

Some of the config file's use INI file headers. So you could use any INI parsers to do the validation and operations.

For Example, In python, you can use ConfigParser

In Perl , user ConfigAbstract

ukanth

Posted 2010-06-22T15:59:11.043

Reputation: 9 930

1That sound good, but I've got to program for that to work (I know perl and python are easy, but I do not use them). With this in mind it should be easy to make a script/program that do what I want to do, but this is what I don't want to do...

So I want to have a program that I can write (in the shell):

configeditor "configfile" "section.item=value" – eloyesp – 2010-06-22T17:53:15.937

1I think I have to downvote this because, as Bobby mentioned in a comment on the question, there are a lot of config files that don't follow the INI format. But for those that do, this is the solution I'd go with. – David Z – 2010-06-22T18:18:50.197

So the answer is NO, there isn't a program/script to achieve this, but can easyly be made for every config file. – eloyesp – 2010-06-24T12:03:35.260

0

You could try crudini

crudini --set /etc/gdm/custom.conf daemon AutomaticLoginEnable 'true;'

pixelbeat

Posted 2010-06-22T15:59:11.043

Reputation: 950

-2

In vi, search for entries with /. Press n to find the next entry. Edit the files at will.

mcandre

Posted 2010-06-22T15:59:11.043

Reputation: 2 696

Asker is asking for an automated solution like adding a setting with a command. addconfig /configfile.conf --key=website --value=SuperUser.com – BloodPhilia – 2010-06-22T18:30:27.173