Reputation: 377
I need to comment out specific lines in .htaccess files for many different websites on a server.
The .htaccess files are in directories like this:
/home/siteA/public_html/.htaccess
/home/siteB/public_html/.htaccess
and so on...
these are the blocks of code I want to comment out from all .htaccess files:
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/bcrunch
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
Ive tried the following:
root@server [/home]# shopt -s globstar
root@server [/home]# sed -i.bak -r '/<IfModule mod_suphp\.c>/,/<\/IfModule>/ s/^/#/; /<Files
"\.user\.ini">/,/<\/Files>/ s/^/#/' **/.htaccess
Ive tested it on a test directory I made with other test sub dirs and test .htaccess files in with the above content and it worked fine but once I run this from /home where I have about 30+ sites it hangs for a long time and just starts using up more and more memory. The problem is that its searching recursively and as there are other .htaccess files in other directories that Im not interested in its just getting bogged down.
So how can I change the above code and tell it to ONLY make changes to all files like this?
/home/siteA/public_html/.htaccess
and ignore other .htacccess files?
Ive been trying to use various find searches but been having no luck so far.
Upvotes: 1
Views: 681
Reputation: 785611
You can use this sed
:
sed '/<IfModule mod_suphp\.c>/,/<\/IfModule>/s/^/#/; /<Files "\.user\.ini">/,/<\/Files>/s/^/#/' file
Combined with find
:
find /home/site*/public_html -name '.htaccess' -exec \
sed -i.bak '/<IfModule mod_suphp\.c>/,/<\/IfModule>/s/^/#/; /<Files "\.user\.ini">/,/<\/Files>/s/^/#/' {} \;
Upvotes: 1