Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to substitute a variable containing a directory path into Apache httpd.conf file????

Reply
Thread Tools

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

 
 
MegaC
Guest
Posts: n/a
 
      05-23-2004
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 Crogram 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 :
Crogram 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 Crogram 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 com.rogers@dmegyesi (for SPAM)

Thanks,
Derek
 
Reply With Quote
 
 
 
 
Jay Tilton
Guest
Posts: n/a
 
      05-23-2004
http://www.velocityreviews.com/forums/(E-Mail 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

 
Reply With Quote
 
 
 
 
MegaC
Guest
Posts: n/a
 
      05-23-2004
(E-Mail Removed) (Jay Tilton) wrote in message news:<(E-Mail Removed)>...
> (E-Mail 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
 
Reply With Quote
 
Brian Helterline
Guest
Posts: n/a
 
      05-24-2004

"MegaC" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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 Crogram 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.

--
brian


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
how to use variable to substitute class's variable? Hans Python 2 03-18-2011 12:31 AM
ruby + apache. need to export path=/opt/ruby/bin every time beforestarting apache ad Ruby 3 12-29-2009 06:40 AM
Eclipse project path containing a variable (linked resouces?) rookeenator@gmail.com Java 3 06-22-2007 06:45 AM
<%= variable does not substitute in user control Steve Richter ASP .Net 5 05-06-2005 05:43 PM



Advertisments