LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Command line INI / config file editor (https://www.linuxquestions.org/questions/linux-software-2/command-line-ini-config-file-editor-728546/)

cioannou 05-26-2009 04:44 AM

Command line INI / config file editor
 
Hello,

What I am trying to do is create an easy way to install a mail server in Debian.

So I want ask the user for some value and then enter that value in PHP.INI or postfix master.cf etc.

Is there any way I can change the config files from command line?

i92guboj 05-26-2009 09:21 AM

"sed" is a stream editor. It can be used to edit files programatically, from command lines or from a script. It's not the friendliest thing in the world though :p

cioannou 05-26-2009 09:25 AM

Thanks,

I already use sed for simple things like replacing xxxx = On to xxxx = Off

the main problem is with postfix master.cf where I need to add/modify lines in a specific place

For example:

in the smtp service line I need to add
Code:

smtp      inet  n      -      -      -      -      smtpd
        -o content_filter=spamassassin


below that I need to add:
Code:

spamassassin unix -    n      n      -      -      pipe
        user=spamd argv=/usr/bin/spamc -f -e
        /usr/sbin/sendmail -oi -f ${sender} ${recipient}
dovecot  unix  -      n      n      -      -      pipe
    flags=DRhu user=vmail:mail argv=/usr/lib/dovecot/deliver -d ${recipient}

Any ideas?

jschiwal 05-26-2009 09:39 AM

You an use pattern matching to select a line and the `a' command to add a line below the one that was matched:
sed '/user=spamd/a\
/usr/sbin/sendmail -oi -f ${sender} ${recipient}' master.cf >master.cf.new

Another technique could be to collect all of the variable parts of master.cf, from the old one & the user, and then construct a new one in it's entirety using a HERE document with variables.

cioannou 05-26-2009 04:21 PM

Thanks will try that


All times are GMT -5. The time now is 05:46 AM.