I am trying to deduce the one liner for an rpm I am packaging to edit a php configuration file from within my spec. The line I am editing looks like:
$conf['nagios_base'] = "/nagios/cgi-bin";
What are the escape requirements Perl needs from within the shell to search for this?
As I have seen, the syntax is a mess, any pointers would be appreciated! thanks, jlc
On 03/16/2011 01:42 PM, Joseph L. Casale wrote:
$conf['nagios_base'] =
I'd just search for that part, above.
Me to, and I never even got to the replacement as the search for that was bailing:)
The problem is trying to pass valid Perl though the bash shell . There is an insane amount of interaction between all the escapings involved in this specific pattern. The hard problem is getting bash to *not* change what you are passing to Perl before Perl sees it.
Use 'echo' as a stand-in for Perl and you will see what is actually being passed to Perl for execution (it most likely isn't what you think it is). Once you know you are feeding Perl the right thing, you can worry about getting the pattern for the substitution correct.
After enough poking and prodding you'll get something like this (after giving up on getting bash to not molest the ' characters before passing them to Perl):
's/($conf[\047nagios_base\047]\s*=\s*")/nagios/cgi-bin";/$1stuffhere";/'
Is there some reason you can't use a straight Perl script instead of using bash to run a perl one liner?
The problem is trying to pass valid Perl though the bash shell . There is an insane amount of interaction between all the escapings involved in this specific pattern. The hard problem is getting bash to *not* change what you are passing to Perl before Perl sees it.
As I have noticed:)
After enough poking and prodding you'll get something like this (after giving up on getting bash to not molest the ' characters before passing them to Perl):
's/($conf[\047nagios_base\047]\s*=\s*")/nagios/cgi-bin";/$1stuffhere";/'
Yup, saw some notes like this, I ended up cheating with a couple of greedy backreferences on both sides of the simple part of the match. Not exactly error proof, but sufficient.
Is there some reason you can't use a straight Perl script instead of using bash to run a perl one liner?
Dunno, just always seen one liners in the %install section to fixup things not adjustable by configure statements...
Thanks! jlc
-----Original Message----- From: Benjamin Franz Sent: Wednesday, March 16, 2011 17:30 To: CentOS mailing list Subject: Re: [CentOS] perl one-liner issue
On 03/16/2011 01:42 PM, Joseph L. Casale wrote:
$conf['nagios_base'] =
I'd just search for that part, above.
Me to, and I never even got to the replacement as the
search for that
was bailing:)
The problem is trying to pass valid Perl though the bash shell . There is an insane amount of interaction between all the escapings involved in this specific pattern. The hard problem is getting bash to *not* change what you are passing to Perl before Perl sees it.
Use 'echo' as a stand-in for Perl and you will see what is actually being passed to Perl for execution (it most likely isn't what you think it is). Once you know you are feeding Perl the right thing, you can worry about getting the pattern for the substitution correct.
After enough poking and prodding you'll get something like this (after giving up on getting bash to not molest the ' characters before passing them to Perl):
'this string isn'"'"'t escaped \n\n :) '
I got used to this a long time ago...
's/($conf[\047nagios_base\047]\s*=\s*")/nagios/cgi-bin";/$
1stuffhere";/'
Is there some reason you can't use a straight Perl script instead of using bash to run a perl one liner?
-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- - - - Jason Pyeron PD Inc. http://www.pdinc.us - - Principal Consultant 10 West 24th Street #100 - - +1 (443) 269-1555 x333 Baltimore, Maryland 21218 - - - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- This message is copyright PD Inc, subject to license 20080407P00.
On Wed, Mar 16, 2011 at 07:56:41PM +0000, Joseph L. Casale wrote:
I am trying to deduce the one liner for an rpm I am packaging to edit a php configuration file from within my spec. The line I am editing looks like:
$conf['nagios_base'] = "/nagios/cgi-bin";
What are the escape requirements Perl needs from within the shell to search for this?
As I have seen, the syntax is a mess, any pointers would be appreciated!
Go easy on yourself, and : a) don't try to match the quotation marks verbatim. Instead, match them with simply a . b) use parenthesis to 'remember' a pattern that you don't want to have to specify again.
E.g. to replace the path on the right-hand-side, do this: (i replaced it with a /; you could of course replace it with whatever you want)
perl -i -ne 's/(^\s*$conf[.nagios_base.] = )./nagios/cgi-bin.;/$1 "/";/; print;' phpConfigFileName
E.g. to delete the line outright: perl -i -ne 'print unless /^\s*$conf[.nagios_base.] = ./nagios/cgi-bin.;/;' phpConfigFileName
Cheers,
Jon
From: Joseph L. Casale jcasale@activenetwerx.com
To: "centos@centos.org" centos@centos.org Sent: Wed, March 16, 2011 8:56:41 PM Subject: [CentOS] perl one-liner issue
I am trying to deduce the one liner for an rpm I am packaging to edit a php configuration file from within my spec. The line I am editing looks like: $conf['nagios_base'] = "/nagios/cgi-bin";
A sed alternative:
sed -i '/nagios_base/ s//nagios/cgi-bin/xxx/' $FILE or more selective: sed -i '/$conf[.nagios_base.] = / s//nagios/cgi-bin/xxx/' $FILE
JD