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

Discussion in 'Perl Misc' started by MegaC, May 23, 2004.

  1. MegaC

    MegaC Guest

    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 com.rogers@dmegyesi (for SPAM)

    Thanks,
    Derek
    MegaC, May 23, 2004
    #1
    1. Advertising

  2. MegaC

    Jay Tilton Guest

    (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
    Jay Tilton, May 23, 2004
    #2
    1. Advertising

  3. MegaC

    MegaC Guest

    (Jay Tilton) wrote in message news:<>...
    > (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
    MegaC, May 23, 2004
    #3
  4. "MegaC" <> wrote in message
    news:...
    > 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.

    --
    brian
    Brian Helterline, May 24, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anders Skar
    Replies:
    3
    Views:
    848
    Anders Skar
    Feb 26, 2004
  2. Ben Jessel
    Replies:
    5
    Views:
    445
    marcus
    Jun 29, 2004
  3. wojciech777
    Replies:
    0
    Views:
    496
    wojciech777
    Nov 5, 2011
  4. Nele Paulsen
    Replies:
    3
    Views:
    171
    A. Sinan Unur
    Dec 17, 2003
  5. Myron

    can I get a new httpd.conf file

    Myron, Feb 8, 2010, in forum: Perl Misc
    Replies:
    19
    Views:
    278
    Steve C
    Feb 10, 2010
Loading...

Share This Page