How to substitute a variable containing a directory path into Apache httpd.conf file????


M

MegaC

Hi all,

I am trying to create a installation script for our product at work.
The script involves prompting the user for the pathname of Apache (and
other components not mentioned here). I then plan to take this
user-entered pathname and edit the http.conf file, by globally
replacing all occurances of a place holder called "APACHE_HOME" with a
ms-dos variable containing the install path entitled %APACHE_HOME%.

So, in my ms-dos script, I have something like this:

.....
set APACHE_HOME=%userManualPathofApache%
....
set PERL_EXE=%IPLANET_HOME/bin/shared/library/perl
@rem Above line is the path to the perl version used by iPlanet
....
%PERL_EXE% -wpe s/APACHE_HOME/"%APACHE_HOME%"/ < httpd.conf >
httpd.conf.mod
move /Y httpd.conf.mod httpd.conf

What I want to happen is for the ms-dos script to call perl to
globally replace all occurances of the placeholder APACHE_HOME with
the interpolated variable of %APACHE_HOME% which contains the install
path of Apache (eg. C:/Program Files/Apache/Apache2). However,
because of the backslashes in the directory name, the substution
strips out the /s and leaves C:program FilesApacheApache2.

I tried changing the delimiter from a / to a #, by this command:
%PERL_EXE% -wpe s#APACHE_HOME#"%APACHE_HOME%"# < httpd.conf >
httpd.conf.mod

but I still get the resulting substitution of :
C:program FilesApacheApache2

I know what your thinking, just get the user to enter C://Program
Files//Apache//Apache2 ... well I tried that and it STILL gives me the
same result of C:program FilesApacheApache2 in the httpd.conf file.

Help!! How do I take the user input of 'C:/Program
Files/Apache/Apache2' and use the command of
%PERL_EXE% -wpe s#APACHE_HOME#"%APACHE_HOME%"# < httpd.conf >
httpd.conf.mod
to substitute every occurance of APACHE_HOME with C:/Program
Files/Apache/Apache2 as intended?

Please help! I am so frustrated by this and it seems like it must be
so easy to do!!

Please respond to [email protected] (for SPAM)

Thanks,
Derek
 
Ad

Advertisements

J

Jay Tilton

(e-mail address removed) (MegaC) wrote:

: Help!! How do I take the user input of 'C:/Program
: Files/Apache/Apache2' and use the command of
: %PERL_EXE% -wpe s#APACHE_HOME#"%APACHE_HOME%"# < httpd.conf >
: httpd.conf.mod
: to substitute every occurance of APACHE_HOME with C:/Program
: Files/Apache/Apache2 as intended?

The shell's interpolation of the environment variable is goofing things up
for perl. Let perl do the interpolation.

perl -wpe s/APACHE_HOME/"$ENV{APACHE_HOME}"/g < httpd.conf > httpd.conf.mod
 
M

MegaC

(e-mail address removed) (MegaC) wrote:

: Help!! How do I take the user input of 'C:/Program
: Files/Apache/Apache2' and use the command of
: %PERL_EXE% -wpe s#APACHE_HOME#"%APACHE_HOME%"# < httpd.conf >
: httpd.conf.mod
: to substitute every occurance of APACHE_HOME with C:/Program
: Files/Apache/Apache2 as intended?

The shell's interpolation of the environment variable is goofing things up
for perl. Let perl do the interpolation.

perl -wpe s/APACHE_HOME/"$ENV{APACHE_HOME}"/g < httpd.conf > httpd.conf.mod

Thanks Jay, but I am still getting the following error:
The system cannot find the file specified.

HELP?!!

Derek
 
Ad

Advertisements

B

Brian Helterline

MegaC said:
Hi all,

I am trying to create a installation script for our product at work.
The script involves prompting the user for the pathname of Apache (and
other components not mentioned here). I then plan to take this
user-entered pathname and edit the http.conf file, by globally
replacing all occurances of a place holder called "APACHE_HOME" with a
ms-dos variable containing the install path entitled %APACHE_HOME%.

So, in my ms-dos script, I have something like this:

....
set APACHE_HOME=%userManualPathofApache%
...
set PERL_EXE=%IPLANET_HOME/bin/shared/library/perl
@rem Above line is the path to the perl version used by iPlanet
...
%PERL_EXE% -wpe s/APACHE_HOME/"%APACHE_HOME%"/ < httpd.conf >
httpd.conf.mod
move /Y httpd.conf.mod httpd.conf

What I want to happen is for the ms-dos script to call perl to
globally replace all occurances of the placeholder APACHE_HOME with
the interpolated variable of %APACHE_HOME% which contains the install
path of Apache (eg. C:/Program Files/Apache/Apache2). However,
because of the backslashes in the directory name, the substution
strips out the /s and leaves C:program FilesApacheApache2.

For DOS, you need your -e parmaters within quotes:

set userManualPathofApache=C:/Program Files/Apache/Apache2
set APACHE_HOME=%userManualPathofApache%
perl -wpe "s'APACHE_HOME'\"%APACHE_HOME%\"'" < httpd.conf > httpd.conf.mod


This will replace APACHE_HOME with "C:/Program Files/Apache/Apache2"

It wasn't clear to me if you wanted the replacement string to contain quotes
or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top