Гость
Как извлечь имя хоста и IP-адрес виртуального хоста из файла конфигурации Apache?
Сообщение
Гость » 13 мар 2024, 14:52
Мне нужно управлять доменными именами (fqdn), печатая их все где-нибудь, возможно, в файле csv. Вся информация находится в файлах конфигурации Apache, мне нужно связать все доменное имя с IP-адресом и портом.
Это пример файла
Код: Выделить всё
ServerName host-6.mydomain.example.org
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-6.mydomain.example.org_access_log 86400" customssl
ServerName www.example.com
ServerAlias www.example.com
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/www.example.com/www.example.com_access_log 86400" customssl
ServerName gimbo.customexample.org
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/gimbo.customexample.org/gimbo.customexample.org_access_log 86400" customssl
ServerName host-6.mydomain.example.org
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-6.mydomain.example.org_access_log 86400" customssl
ServerName host-6.mydomain.example.org
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-6.mydomain.example.org_ssl_access_log 86400" customssl
IncludeOptional conf.d/star_mydomain_example_org.cnf
ServerName host-6.mydomain.example.org
ServerAlias www.example.org www.pollo.biz www.pollone.mondo
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-6.mydomain.example.org_access_log 86400" customssl
ServerName host-7.mydomain.example.org
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-7.mydomain.example.org/host-7.mydomain.example.org_access_log 86400" customssl
ServerName host-7.mydomain.example.org
ErrorLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-7.mydomain.example.org/host-7.mydomain.example.org_ssl_error_log 86400"
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-7.mydomain.example.org/host-7.mydomain.example.org_ssl_access_log 86400" customssl
IncludeOptional conf.d/star_mydomain_example_org.cnf
Это домены (fqdn)
Код: Выделить всё
gimbo.customexample.org
host-6.mydomain.example.org
host-7.mydomain.example.org
www.example.biz
www.example.com
www.example.org
www.pollo.biz
www.pollone.mondo
Мне нужен этот вывод:
Код: Выделить всё
host-6.mydomain.example.org,10.11.12.21,80
www.example.com,10.11.12.21,80
www.example.com,10.11.12.21,80
www.example.biz,10.11.12.21,80
gimbo.customexample.org,10.11.12.21,80
host-6.mydomain.example.org,10.11.12.22,80
host-6.mydomain.example.org,10.11.12.22,443
host-6.mydomain.example.org,10.11.12.22,8080
www.example.org,10.11.12.22,8080
www.pollo.biz,10.11.12.22,8080
www.pollone.mondo,10.11.12.22,8080
host-7.mydomain.example.org,10.11.12.22,80
host-7.mydomain.example.org,10.11.12.22,443
Что я пробовал:
Код: Выделить всё
awk -v n=2 -e '/^\s*Server(Name|Alias)/ { for (i=n; i
Источник: [url]https://stackoverflow.com/questions/78152597/how-can-i-extract-hostname-and-virtual-host-ip-address-from-an-apache-config-fil[/url]
1710330759
Гость
Мне нужно управлять доменными именами (fqdn), печатая их все где-нибудь, возможно, в файле csv. Вся информация находится в файлах конфигурации Apache, мне нужно связать все доменное имя с IP-адресом и портом. Это пример файла [code] ServerName host-6.mydomain.example.org CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-6.mydomain.example.org_access_log 86400" customssl ServerName www.example.com ServerAlias www.example.com CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/www.example.com/www.example.com_access_log 86400" customssl ServerName gimbo.customexample.org CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/gimbo.customexample.org/gimbo.customexample.org_access_log 86400" customssl ServerName host-6.mydomain.example.org CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-6.mydomain.example.org_access_log 86400" customssl ServerName host-6.mydomain.example.org CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-6.mydomain.example.org_ssl_access_log 86400" customssl IncludeOptional conf.d/star_mydomain_example_org.cnf ServerName host-6.mydomain.example.org ServerAlias www.example.org www.pollo.biz www.pollone.mondo CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-6.mydomain.example.org_access_log 86400" customssl ServerName host-7.mydomain.example.org CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-7.mydomain.example.org/host-7.mydomain.example.org_access_log 86400" customssl ServerName host-7.mydomain.example.org ErrorLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-7.mydomain.example.org/host-7.mydomain.example.org_ssl_error_log 86400" CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/host-7.mydomain.example.org/host-7.mydomain.example.org_ssl_access_log 86400" customssl IncludeOptional conf.d/star_mydomain_example_org.cnf [/code] Это домены (fqdn) [code]gimbo.customexample.org host-6.mydomain.example.org host-7.mydomain.example.org www.example.biz www.example.com www.example.org www.pollo.biz www.pollone.mondo [/code] Мне нужен этот вывод: [code]host-6.mydomain.example.org,10.11.12.21,80 www.example.com,10.11.12.21,80 www.example.com,10.11.12.21,80 www.example.biz,10.11.12.21,80 gimbo.customexample.org,10.11.12.21,80 host-6.mydomain.example.org,10.11.12.22,80 host-6.mydomain.example.org,10.11.12.22,443 host-6.mydomain.example.org,10.11.12.22,8080 www.example.org,10.11.12.22,8080 www.pollo.biz,10.11.12.22,8080 www.pollone.mondo,10.11.12.22,8080 host-7.mydomain.example.org,10.11.12.22,80 host-7.mydomain.example.org,10.11.12.22,443 [/code] Что я пробовал:[code]awk -v n=2 -e '/^\s*Server(Name|Alias)/ { for (i=n; i Источник: [url]https://stackoverflow.com/questions/78152597/how-can-i-extract-hostname-and-virtual-host-ip-address-from-an-apache-config-fil[/url]