The output of apachectl -S
is really useful but it's not easy to parse in a script. To make it easier to find the configuration file for a given NameVirtualHost host the following BASH one liner returns lines of output that can be easily parsed.
# apachectl -S 2>&1 \
| sed -rn -e '/NameVirtualHost$/,$ { /NameVirtualHost$/d; $ d; p; }' \
| sed -rn -e 's/^.*(port ([0-9]+) namevhost|alias) ([^ ]*)( )?(\((.*):[0-9]+\)|$)/\2 \6\n\3/p' \
| sed -r -e '/^$/d' -e 's/(.*\.conf$)/\n\1/g' \
| awk -vRS='' '$1=$1' \
| sort -n \
| uniq