I am trying to add multiple lines to a configuration file in the second occurrence of a string. I can get my While loop to append the code to the end of the file, but it needs to be inserted below a certain line and above another
<$site_conf tr '\n' '\0' |
sed -e "s/.*/$(yes '\0' | head -n 1 | tr -d '\n')/g" |
tr '\0' '\n' >> $site_conf
sed -i '0,/*:80/! {0,/*:80/ s/*:80/*:443/}' $site_conf
TEMPLATE='SSLEngine.txt'
while read LINE; do
echo $LINE |
sed 's/${SSLplaceholder}/'${SSLdomain}'/' >> $site_conf
done < $TEMPLATE;;
This produces a config file like so:
<VirtualHost *:80>
ServerName mysite.preview.something.com
DocumentRoot /home/mysite/web/content
<Directory /home/mysite/web/content>
Options +FollowSymLinks -Indexes
AllowOverride All
Require all granted
</Directory>
LogLevel warn
ErrorLog /home/mysite/web/log/mysite-error.log
CustomLog /home/mysite/web/log/mysite-access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName mysite.preview.something.com
DocumentRoot /home/mysite/web/content
<Directory /home/mysite/web/content>
Options +FollowSymLinks -Indexes
AllowOverride All
Require all granted
</Directory>
LogLevel warn
ErrorLog /home/mysite/web/log/mysite-error.log
CustomLog /home/mysite/web/log/mysite-access.log combined
</VirtualHost>
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile /etc/apache2/ssl/domain.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/private/domain.com.key
SSLCertificateChainFile /etc/apache2/ssl/int.crt
I want the final 6 lines to be inserted under the second ServerName line and before the DocumentRoot line. Any ideas?
ServerNameline, and inserting the six lines. Inserting the six lines is easy with sed'srcommand, but I'm having some trouble finding the secondServerNameline...