Find the answer to your Linux question:
Results 1 to 2 of 2
I need to add a snippet of php code to about 150 'index.html' files on one of my servers... So far I have this: Code: for a in $(grep DocumentRoot ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    2

    Find and replace bash script?

    I need to add a snippet of php code to about 150 'index.html' files on one of my servers...

    So far I have this:
    Code:
    for a in $(grep DocumentRoot /etc/httpd/conf/httpd.conf |awk '{print $2}');do sed (not sure here) $a/html/index.html;done
    So far this will find every domain I have on the server and give it value 'a'... domain1.org, domain2.org etc

    The 'do sed' is the part I need help with. I need to find "</body>" in every index.html file and replace it with:
    Code:
    "<?php 
    $GLOBALS['adl_page_prefix']='$a.org';
    $GLOBALS['adl_ext_addr']='stats.domain.com';
    @include_once $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'].'/twatch_include/extlogger.php';
    ?>
    </body>"
    Is this possible? Thanks so much to anyone that can help, will save me a LOT of time
    Last edited by devils casper; 03-10-2008 at 07:31 PM. Reason: added [code]...[/code] tags.

  2. #2
    Just Joined!
    Join Date
    Mar 2008
    Posts
    2
    Code:
    for file in ls /home/webadmin/xander/videos.html ; do
    sed -e 's/<\/html>/<\?php 
    \$GLOBALS[\'adl_page_prefix\']=\'domain.org\';
    \$GLOBALS[\'adl_ext_addr\']=\'stats.domain.com\';
    @include_once \$GLOBALS[\'HTTP_SERVER_VARS\'][\'DOCUMENT_ROOT\'].'\/twatch_include\/extlogger.php';
    \?>/g' "$file"
    echo ----------------------------------------------------------------
    done
    Did I escape this correctly? Can I even insert php code using sed?

Posting Permissions

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