5

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?

Keeper
  • 51
  • 1
  • 2

2 Answers2

6

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

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
0

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.

SmallClanger
  • 9,127
  • 1
  • 32
  • 47