[PLUG] replacing lines in a httpd.conf file

Richard Kurth rkurth at starband.net
Sat Nov 16 19:45:33 UTC 2002


Hello Russell,
I just ran this and I get this error message
sed: -e expression #5, char 23: Extra characters after command

I removed the last -e expression and the script works. It looks like it
does not like the ~ in this line ' -e '/$rewrite_rules =~ s/proto/$proto/g;/a\
because that is char 23 what can I do to fix that. will a \ work to
make sed not read that as a Command

Also it added everything except these two lines
' -e '/$proto = 'https';/a\
    $portnumber = '5001';
' -e '/$proto = 'http';/a\
   $portnumber = '5000';

   Is that because of the '' around https and http if so do I put a \
   in front of them so sed does not read that as a Command


Saturday, November 16, 2002, 10:43:18 AM, you wrote:


RE> You can use the option -e multiple times in one call of sed. I didn't see in
RE> your pattern matches where the following pattern relied on the proceeding
RE> pattern being in the file, so I believe you can combine them into one call. I
RE> might have missed something though. 

RE> #!/bin/sh

RE> ORGINAL=/tmp/TESTSCRIPT/httpd.conf 
RE> KOPY=/tmp/TESTSCRIPT/httpd.conf.autocontrol
RE> OUTPUT=/tmp/TESTSCRIPT/httpd.conf.new

RE> cp $ORGINAL $KOPY

RE> sed -e '/my (@ssl_conf,$ip,$group,$rewrite_rules,$proto,$ret);/a\
RE> my ($portnumber);
RE> ' -e '/$proto = 'https';/a\
RE>     $portnumber = '5001';
RE> ' -e '/$proto = 'http';/a\
RE>    $portnumber = '5000';
RE> ' -e '/RewriteRule .*cgi-bin\/.cobalt.* proto:\/\/servername:81.*/a\
RE> ### Begin - Autocontrol ###\
RE> RewriteCond %{HTTP_HOST}                ^([^:]+)\
RE> RewriteRule ^/acp/?$                    
RE> proto://servername:portnumber/autocontrol/index.php\
RE> RewriteCond %{HTTP_HOST}               ^([^:]+)\
RE> RewriteRule ^/ucp/?$                    
RE> proto://servername:portnumber/user/index.php\
RE> RewriteCond %{HTTP_HOST}                ^([^:]+)\
RE> RewriteRule ^/rcp/?$                    
RE> proto://servername:portnumber/resellerpanel/index.php\
RE> ### End - Autocontrol ###\
RE> ' -e '/$rewrite_rules =~ s/proto/$proto/g;/a\
RE> $rewrite_rules =~ s/portnumber/$portnumber/g;
RE> ' < $ORGINAL > $OUTPUT

RE> mv $OUTPUT $ORGINAL

RE> exit 0

RE> Thank you
RE> Russell



RE> On Sat, 16 Nov 2002 00:29:54 -0800, Richard Kurth said:

>> 
>>  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
>>  
>>  
>>  
>>    
>>  


RE> _______________________________________________
RE> PLUG mailing list
RE> PLUG at lists.pdxlinux.org
RE> http://lists.pdxlinux.org/mailman/listinfo/plug



-- 
Best regards,
 Richard                            mailto:rkurth at starband.net





More information about the PLUG mailing list