Bash script to retrieving virtual hosts info from httpd.conf
Hello,
I am trying to make a bash script for my nginx server because i use cPanel and they do not include nginx and it is a plugin. So i am trying to make a bash script so it looks in to the httpd.conf file for every virtual hosts that have SSL installed and to build the nginx ssl conf file and copy the cert, key and caboundle files to a ssl folder in nginx. my script is working but need fine tuning on the coding because right now it loops ever virtual hosts and i only need it to loop only the virtual hosts that use port 443 and have no idea how to do it. I also notice that in my httpd.conf file there is virtual hosts that are the domain mail that are using mail.domain.com and my script is not including them. I know my script not pretty but it works and i am not a programmer and did a lot of googling. is there a way to change the awk to only look for all <VirtualHost*:443> ? Code:
#!/bin/bash |
As the main concern is the awk I will keep my focus there. If you only wish to return those using 443 then make that an item you look for so that when you enter the 'p' portion of your script you can test
to see if that was found. Code:
p{if(443 was found)print out;p=0;out=""} |
|
Quote:
|
Yeah, stepped right in it at 6:04am local.
I'm out. Peace and Coffee. |
Yes Habitual part of the code was from that post because i am not a programmer and when i google to see how to look in the httpd.conf file that post came up and was what i was looking for.
I changed my awk to use this Code:
p{if(443 was found)print out;p=0;out=""} Code:
p{print out;p=0;out=""} I forgot to ask is there a way to search for 2 different ports 443 and 444 because with my nginx plugin the apache SSL port is changed to 444 and it's also changed in the httpd.conf file. |
ummm ... not exactly that?? Sorry if I assumed too much, but you will need to set a variable which is looking for the presence of the string '443' and if it is found you set the variable to true (a 1 will suffice) and then use the 'if' to see if the variable is set to 1.
Let me know if that clears that up? |
Quote:
|
The same way you set the variables p and out. So if you called it 'port_found', you would need to check the line contains '443', like you did for 'ServerName' and once found it is simply:
Code:
port_found = 1 If you can code in php, this shouldn't seem to foreign :) |
Quote:
|
Shouldn't be a problem as each line will still be processed. Give it a try :)
|
Hello,
I added ServerAlias to my awk command but ServerAlias holders multiple domains that is like this Code:
ServerAlias mail.domain.com sub.domain.com |
Quote:
Code:
awk '/ServerAlias/ { for ( i=2; i <= NF; i++ ) { serveralias[$i]++ }; } END { for ( server in serveralias) { print server } }' |
All times are GMT -5. The time now is 08:35 PM. |