Solved Help with perl search replace script

Hello,
I wrote a little script to change the setting in my /usr/local/etc/php.ini file
Code:
#!/bin/sh
#
INIFILE="/usr/local/etc/php.ini"
perl -p -i -e '
s/.*memory_limit.*/memory_limit = 32M/;
s/.*upload_max_filesize.*/upload_max_filesize = 3M/;
s/.*post_max_size.*/post_max_size = 2M/;
s/.*cgi.fix_pathinfo.*/cgi.fix_pathinfo = 0/;
s/.*disable_functions.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority/;
s/.*expose_php.*/expose_php = Off/;
s/.*max_execution_time.*/max_execution_time = 30/;
s/.*max_input_time.*/max_input_time = 60/;
s/.*display_errors.*/display_errors = Off/;
s/.*file_uploads.*/file_uploads = On/;
s/.*upload_max_filesize.*/upload_max_filesize = 2M/;
s/.*allow_url_include.*/allow_url_include = Off/;
s/.*;date.timezone.*/date.timezone = Europe/London/;
' "$INIFILE"
When I try to run it, Iget the following error:
Code:
Unknown regexp modifier "/L" at -e line 14, at end of line
Unknown regexp modifier "/n" at -e line 14, at end of line
Unknown regexp modifier "/n" at -e line 14, at end of line
syntax error at -e line 14, near "/;"
Execution of -e aborted due to compilation errors.

Could someone please help me out?
 
A backslashed character escape "\" should do it as well

Code:
s/.*;date.timezone.*/date.timezone = Europe[b]\[/b]/London/;

But I cannot resist: Why not using a pure Perl script?
 
If that's the whole script and you're interested in a pure perl version, here's an untested script. After making it executable ( chmod u+x my_script), run it like myscript /usr/local/bin/php.ini > ~/php.ini.new. It assumes perl is installed in /usr/local/bin/.

Code:
#!/usr/local/bin/perl -p

use strict;
use warnings;

s/.*memory_limit.*/memory_limit = 32M/;
s/.*upload_max_filesize.*/upload_max_filesize = 3M/;
s/.*post_max_size.*/post_max_size = 2M/;
s/.*cgi.fix_pathinfo.*/cgi.fix_pathinfo = 0/;
s/.*disable_functions.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority/;
s/.*expose_php.*/expose_php = Off/;
s/.*max_execution_time.*/max_execution_time = 30/;
s/.*max_input_time.*/max_input_time = 60/;
s/.*display_errors.*/display_errors = Off/;
s/.*file_uploads.*/file_uploads = On/;
s/.*upload_max_filesize.*/upload_max_filesize = 2M/;
s/.*allow_url_include.*/allow_url_include = Off/;
s/.*;date.timezone.*/date.timezone = Europe\/London/;
 
Thank you for taking the time to write this for me jrm :)

This is a small part of a bigger script. Can I call this perl script in my sh script by calling it like this?
Code:
echo "This script is about to run another script."
sh ./script.sh
echo "This script has just run another script."
 
Back
Top