views:

50

answers:

2

I will better explain my situation with an example.

Considering a httpd.conf file in which I need to change the document root. So first I need to find the ServerName then change the document root, so I believe here I need two regexp but I m not sure how to do it?Can someone please help?Or do I just need to find the ServerName and make a note of the line number then proceed with finding the DocumentRoot using a script? Thanks.

A: 

I am not sure, but maybe something like this will work for you.

cat /etc/apache2/http.conf | sed 's/.*ServerName=.*/ServerName=YourNewLocation/' > tmp
mv tmp /etc/apache2/http.conf
kogut
Sorry, I didn't read Your question carrefully... My answer won't help
kogut
A: 

i am not sure why you need to search for ServerName first, but here's how you can change documentroot

awk '/^DocumentRoot/{$0="DocumentRoot /new/root" } {print}' /path/httpd.conf  > temp
mv temp /path/httpd.conf 

Or if you are making use of ServerName value to create your new root,

awk '$1~/ServerName/{servername=$2}
/^DocumentRoot/{
 $0="DocumentRoot "servername  # create your new root here.
}
{print}
' /path/httpd.conf > temp
mv temp /path/httpd.conf
ghostdog74
Your version will change all the DocumentRoot's present in the config file. This is the reason I need to find the a virtual host entry using the ServerName and the change its DocumentRoot. Thanks for your reply.
mike