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 ...
- 03-10-2008 #1Just 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:
So far this will find every domain I have on the server and give it value 'a'... domain1.org, domain2.org etcCode:for a in $(grep DocumentRoot /etc/httpd/conf/httpd.conf |awk '{print $2}');do sed (not sure here) $a/html/index.html;done
The 'do sed' is the part I need help with. I need to find "</body>" in every index.html file and replace it with:
Is this possible? Thanks so much to anyone that can help, will save me a LOT of timeCode:"<?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>"
Last edited by devils casper; 03-10-2008 at 07:31 PM. Reason: added [code]...[/code] tags.
- 03-11-2008 #2Just Joined!
- Join Date
- Mar 2008
- Posts
- 2
Did I escape this correctly? Can I even insert php code using sed?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


Reply With Quote