Find the answer to your Linux question:
Results 1 to 5 of 5
I want to write a script that auto modify httpd.conf. I want to ADD a line "ServerName XXXXX" and REPLACE the DocumentRoot Any hints? thanks....
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    2

    Script add/replace string in file

    I want to write a script that auto modify httpd.conf.
    I want to ADD a line "ServerName XXXXX"
    and
    REPLACE the DocumentRoot

    Any hints? thanks.

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    have you tried sed command?
    man sed
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Just Joined!
    Join Date
    May 2006
    Posts
    4
    Quote Originally Posted by uativan View Post
    I want to write a script that auto modify httpd.conf.
    I want to ADD a line "ServerName XXXXX"
    and
    REPLACE the DocumentRoot

    Any hints? thanks.
    Follwing is the simple shell script to auto modify your httpd.conf. Modify path in script accordingly


    #for adding a line, append the line in httpd.conf
    echo "ServerName XXXXX" >> httpd.conf
    #for replacing, use sed or grep command, using grep
    grep -v "DocumentRoot" httpd.conf >httpd.conf.tmp
    echo "DocumentRoot your_document_root_path" >>httpd.conf.tmp
    mv httpd.conf.tmp httpd.conf

  4. #4
    Just Joined!
    Join Date
    Dec 2009
    Posts
    5
    Use Vi editor:
    %s/string-to-replace/replace-with-string/

  5. #5
    Just Joined!
    Join Date
    Dec 2009
    Posts
    5
    find . -type f -exec sed -i -e 's/DocumentRoot/ServerName XXXXX/g' {} \;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...