[PLUG] replacing lines in a httpd.conf file
Richard Kurth
rkurth at starband.net
Sat Nov 16 08:29:54 UTC 2002
I need to replace a series of lines in a httpd.conf file on the fly.
So it needs to be done in a bash file. I have been trying a bunch of
different ways mostly with sed. It seams there would be a cleaner way
to do it. Below is what I have so far. There are five different
sections that have to be changed or have lines added to them.
Is there a better way of doing this?
cp /tmp/TESTSCRIPT/httpd.conf /tmp/TESTSCRIPT/httpd.conf.autocontrol
sed -e '/my (@ssl_conf,$ip,$group,$rewrite_rules,$proto,$ret);/a\
my ($portnumber);
' < /tmp/TESTSCRIPT/httpd.conf > /tmp/TESTSCRIPT/.httpd.new
cp /tmp/TESTSCRIPT/.httpd.new /tmp/TESTSCRIPT/httpd.conf
rm /tmp/TESTSCRIPT/.httpd.new
sed -e '/$proto = 'https';/a\
$portnumber = '5001';
' < /tmp/TESTSCRIPT/httpd.conf > /tmp/TESTSCRIPT/.httpd.new
cp /tmp/TESTSCRIPT/.httpd.new /tmp/TESTSCRIPT/httpd.conf
rm /tmp/TESTSCRIPT/.httpd.new
sed -e '/$proto = 'http';/a\
$portnumber = '5000';
' < /tmp/TESTSCRIPT/httpd.conf > /tmp/TESTSCRIPT/.httpd.new
cp /tmp/TESTSCRIPT/.httpd.new /tmp/TESTSCRIPT/httpd.conf
rm /tmp/TESTSCRIPT/.httpd.new
sed -e '/RewriteRule .*cgi-bin\/.cobalt.* proto:\/\/servername:81.*/a\
### Begin - Autocontrol ###\
RewriteCond %{HTTP_HOST} ^([^:]+)\
RewriteRule ^/acp/?$ proto://servername:portnumber/autocontrol/index.php\
RewriteCond %{HTTP_HOST} ^([^:]+)\
RewriteRule ^/ucp/?$ proto://servername:portnumber/user/index.php\
RewriteCond %{HTTP_HOST} ^([^:]+)\
RewriteRule ^/rcp/?$ proto://servername:portnumber/resellerpanel/index.php\
### End - Autocontrol ###\
' < /tmp/TESTSCRIPT/httpd.conf > /tmp/TESTSCRIPT/.httpd.new
cp /tmp/TESTSCRIPT/.httpd.new /tmp/TESTSCRIPT/httpd.conf
rm /tmp/TESTSCRIPT/.httpd.new
sed -e '/$rewrite_rules =~ s/proto/$proto/g;/a\
$rewrite_rules =~ s/portnumber/$portnumber/g;
' < /tmp/TESTSCRIPT/httpd.conf > /tmp/TESTSCRIPT/.httpd.new
cp /tmp/TESTSCRIPT/.httpd.new /tmp/TESTSCRIPT/httpd.conf
rm /tmp/TESTSCRIPT/.httpd.new
--
Best regards,
Richard mailto:rkurth at starband.net
More information about the PLUG
mailing list