Apache vhost - block treatment
Apache vhost - block treatment
(OP)
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/www/html/ SSLEngine on SSLProxyEngine on SSLCertificateFile /etc/httpd/ssl/company.crt SSLCertificateKeyFile /etc/httpd/ssl/company.key SSLCertificateChainFile /etc/httpd/ssl/gsdomainvalsha2g2r1.pem ProxyPass /stat https://srv.compagny.org/stat ProxyPassReverse /stat https://srv.compagny.org/stat </VirtualHost> <VirtualHost *:443> ServerName site2.compagny.org DocumentRoot /var/www/html/ SSLEngine on SSLProxyEngine on SSLCertificateFile /etc/httpd/ssl/company.crt SSLCertificateKeyFile /etc/httpd/ssl/company.key SSLCertificateChainFile /etc/httpd/ssl/gsdomainvalsha2g2r1.pem ProxyPass /office https://srv2.compagny.org/office ProxyPassReverse /office https://srv2.compagny.org/office ProxyPass /home https://srv2.compagny.org/home ProxyPassReverse /home https://srv2.compagny.org/home </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.
RE: Apache vhost - block treatment
I tried this
frial.sh
CODE
and got the result
CODE
RE: Apache vhost - block treatment
Thank you very much for your help, that's perfect
I thought I would have to process the files by blocks, but that was not a good idea.
RE: Apache vhost - block treatment
awk processes the files column-wise. The default field separator is space, so it is as you would have in the file these 3 columns:
RE: Apache vhost - block treatment
As I looked at the table, which screenshot I posted before, I saw that the script can be greatly simplified:
CODE
RE: Apache vhost - block treatment
When vhost doesn't contain "ProxyPass" value, when I read those scripts, I think output is empty.
I must call print function after set variables no?
RE: Apache vhost - block treatment
CODE
RE: Apache vhost - block treatment
I hadn't thought of doing this so simply, thank you very much!
I added one more condition if vhost does'nt contain servername:
CODE -->