Solved [Solved] problem with small perl script

fred974

Daemon

Reaction score: 37
Messages: 1,584

Hello all,

Could someone tell me if they can spot my mistake in the bollow script?
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 = 10M/;
s/.*post_max_size.*/post_max_size = 20M/;
' "$INIFILE"

PHPPFMFILE="/usr/local/etc/php-fpm.conf"
perl -p -i -e '
s/.*;events.mechanism.*/events.mechanism = kqueue/;
s/.*listen.*/listen = /var/run/php-fpm.sock/;
s/.*;listen.owner.*/listen.owner = www/;
s/.*;listen.group.*/listen.group = www/;
s/.*;listen.mode.*/listen.mode = 0666/;
' "$PHPPFMFILE"
This is the error message that I am getting:
Code:
Having no space between pattern and following word is deprecated at -e line 3.
Bareword found where operator expected at -e line 3, near "s/.*listen.*/listen = /var"
syntax error at -e line 3, near "s/.*listen.*/listen = /var"
Execution of -e aborted due to compilation errors.
Thank you in advance

Fred
 

usdmatt

Daemon

Reaction score: 521
Messages: 1,399

Re: problem with small perl script

Code:
s/.*listen.*/listen = /var/run/php-fpm.sock/;
I suspect Perl is interpreting the / just before var as the end of the pattern. You'll probably need to escape the slashes in the path with backslashes. That or choose a different character to denote the start and end of the pattern/replacement.
 

junovitch@

Daemon
Developer

Reaction score: 617
Messages: 1,773

Re: problem with small perl script

The '/' character would certainly have to be escaped in this context. So you would need a '\/' to get a literal slash. That gets ugly quickly though. Here's an example that I've used using '^' to break apart the substitution strings to avoid the need to escape a '/'. Perl isn't picky about what characters you use there.

Code:
perl -pwi -e 's^#ZPOOL=tank^ZPOOL=zfs^g' poudriere.conf
perl -pwi -e 's^_PROTO_://_CHANGE_THIS_^ftp://ftp.freebsd.org^g' poudriere.conf
perl -pwi -e 's^BASEFS=/usr/local/poudriere^BASEFS=/zfs/poudriere^g' poudriere.conf
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 7,751
Messages: 30,832

Re: problem with small perl script

Strictly speaking this isn't a Perl script but a shell script that uses Perl ;)

And why the overkill of Perl? Why not use sed(1)? The only thing you seem to use is search and replace.

Instead of a / it's quite common to see |. Makes it somewhat readable too.

perl -pwi -e 's|#ZPOOL=tank|ZPOOL=zfs|g' poudriere.conf
 
OP
OP
fred974

fred974

Daemon

Reaction score: 37
Messages: 1,584

Re: problem with small perl script

Thank you very much.
That was a big help :)
 
Top