Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Basically, I'm trying to setup a shell script that lets me autoconfigure some parameters on my new servers

In particular, I'd like to set, in php.ini

error_log= /var/log/php_errors.log error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

In my bash script I have this:

ERROR_REPORTING="error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED"
ERROR_LOG="/var/log/php_errors.log"

#CREATE LOG FILE 
sed -i 's/error_reporting = .*/error_reporting = '${ERROR_REPORTING}'/' /etc/php.ini
touch $ERROR_LOG
chown apache:apache $ERROR_LOG
#The ; in the next line is because the line is commented by default on RHEL5
sed -i 's/;error_log = .*/error_log = '${ERROR_LOG}'/' /etc/php.ini

However, this does not appear to work and the error is not obvious to me..could anybody please correct my error?

share|improve this question
    
It would help if you were specific regarding how it does not appear to work and also posted the error message. –  Dennis Williamson Dec 11 '10 at 21:10

2 Answers 2

You need to change the outermost single quotes to double quotes and remove the single quotes around the variable names.

ERROR_REPORTING="E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED"
ERROR_LOG="/var/log/php_errors.log"

#CREATE LOG FILE 
sed -i "s/error_reporting = .*/error_reporting = ${ERROR_REPORTING}/" /etc/php.ini
touch $ERROR_LOG
chown apache:apache $ERROR_LOG
#The ; in the next line is because the line is commented by default on RHEL5
sed -i "s/;error_log = .*/error_log = ${ERROR_LOG}/" /etc/php.ini

Note that I also changed the first variable and the related sed command so it parallels the other set.

I'm assuming the error message you were getting was "unterminated `s' command".

share|improve this answer

sed -i requires an argument that is used as the suffix for the backup file it creates.

Example: sed -i .bak 's/old/new/' testfile will create a backup testfile.bak before editing the original in place. Your command is taking the command string as the backup suffix (and, naturally, failing).

I'd also use double quotes on the command string. It'll save you having to mess around with extra single quoutes around the variable expansion.

share|improve this answer
1  
That's true on OS X. GNU sed (which is what the OP is using in RHEL) does not require a suffix (it will accept an optional one). –  Dennis Williamson Dec 11 '10 at 21:19
    
Oh dear. I've spent the last 8-10 years thinking sed required that suffix :D. –  SmallClanger Dec 11 '10 at 21:32

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.