I have several Apache vHost configurations across several hosts. I'm trying to write a Bash script that will iterate through each host and search the .conf
file on each one, pulling out the first (only the first) <VirtualHost>
block. I've tried writing a regex to match it, but it's just not working. Here's the code I've tried:
#!/bin/bash
egrep -o '(\<VirtualHost\>)(.*)(\<\/VirtualHost\>)' -m1
Since .*
doesn't match newlines, I even tried this:
#!/bin/bash
egrep -o '(\<VirtualHost\>)(.*[\S]*)(\<\/VirtualHost\>)' -m1
I still get nothing. :-(
I don't understand what I'm doing wrong here. Here is a sample of the data I'm trying to match:
<VirtualHost apache-frontend:80>
ServerAdmin mysite@domain.com
ServerName domain.com
DocumentRoot /path/to/my/doc/root
RewriteEngine On
Include include.d/global/rewrite.conf
RewriteRule ^(.*)$ http://www.domain.com$1 [R=301,L]
</VirtualHost>
<VirtualHost apache-frontend:80>
ServerAdmin mysite@domain.com
ServerName domain.com
DocumentRoot /path/to/my/doc/root
RewriteEngine On
Include include.d/global/rewrite.conf
RewriteRule ^(.*)$ http://www.domain.com$1 [R=301,L]
</VirtualHost>
<VirtualHost apache-frontend:80>
ServerAdmin mysite@domain.com
ServerName domain.com
DocumentRoot /path/to/my/doc/root
RewriteEngine On
Include include.d/global/rewrite.conf
RewriteRule ^(.*)$ http://www.domain.com$1 [R=301,L]
</VirtualHost>