Hi all,
I'm a beginner's awk.
I have a file apache like this:
I want parsing block by block, catch ServerName and ProxyPass and print out like this:
Vhost#site1.compagny.org/stat
Vhost#site2.compagny.org/office
Vhost#site2.compagny.org/home
I go step by step and want print just Servname actually, but I'm so bad, this command print only last Servername.
awk '/<VirtualHost/,/<\/VirtualHost>/ { if ($0 ~ "ServerName" ) srv=$2 }; END { print srv }' sites.conf
I known awk command is powerfull, but little complex for beginner ^^.
Thanks for your help.
I'm a beginner's awk.
I have a file apache like this:
Code:
<VirtualHost *:443>
ServerName site1.compagny.org
DocumentRoot /var/[URL unfurl="true"]www/html/[/URL]
SSLEngine on
SSLProxyEngine on
SSLCertificateFile /etc/httpd/ssl/company.crt
SSLCertificateKeyFile /etc/httpd/ssl/company.key
SSLCertificateChainFile /etc/httpd/ssl/gsdomainvalsha2g2r1.pem
ProxyPass /stat [URL unfurl="true"]https://srv.compagny.org/stat[/URL]
ProxyPassReverse /stat [URL unfurl="true"]https://srv.compagny.org/stat[/URL]
</VirtualHost>
<VirtualHost *:443>
ServerName site2.compagny.org
DocumentRoot /var/[URL unfurl="true"]www/html/[/URL]
SSLEngine on
SSLProxyEngine on
SSLCertificateFile /etc/httpd/ssl/company.crt
SSLCertificateKeyFile /etc/httpd/ssl/company.key
SSLCertificateChainFile /etc/httpd/ssl/gsdomainvalsha2g2r1.pem
ProxyPass /office [URL unfurl="true"]https://srv2.compagny.org/office[/URL]
ProxyPassReverse /office [URL unfurl="true"]https://srv2.compagny.org/office[/URL]
ProxyPass /home [URL unfurl="true"]https://srv2.compagny.org/home[/URL]
ProxyPassReverse /home [URL unfurl="true"]https://srv2.compagny.org/home[/URL]
</VirtualHost>
[...]
I want parsing block by block, catch ServerName and ProxyPass and print out like this:
Vhost#site1.compagny.org/stat
Vhost#site2.compagny.org/office
Vhost#site2.compagny.org/home
I go step by step and want print just Servname actually, but I'm so bad, this command print only last Servername.
awk '/<VirtualHost/,/<\/VirtualHost>/ { if ($0 ~ "ServerName" ) srv=$2 }; END { print srv }' sites.conf
I known awk command is powerfull, but little complex for beginner ^^.
Thanks for your help.