Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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).

share|improve this question
8  
conf 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 Jun 22 '10 at 17:22
    
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 Jun 23 '10 at 15:39

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer
    
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 Dec 13 '11 at 3:45
    
And what you need is the desktop.aug module. –  ℝaphink May 9 '12 at 21:35

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

share|improve this answer
1  
That 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" –  El_Hoy Jun 22 '10 at 17:53
1  
I 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 Jun 22 '10 at 18:18
    
So the answer is NO, there isn't a program/script to achieve this, but can easyly be made for every config file. –  El_Hoy Jun 24 '10 at 12:03

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

share|improve this answer
    
Asker is asking for an automated solution like adding a setting with a command. addconfig /configfile.conf --key=website --value=SuperUser.com –  BloodPhilia Jun 22 '10 at 18:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.