Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jdeathe/7e2d236b2d13e05cac2c349eac4196a0 to your computer and use it in GitHub Desktop.

Select an option

Save jdeathe/7e2d236b2d13e05cac2c349eac4196a0 to your computer and use it in GitHub Desktop.

Revisions

  1. jdeathe revised this gist May 30, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get-apache-namevhost-alias-to-configs.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    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 host the following BASH one liner returns lines of output that can be easily parsed.
    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 \
  2. jdeathe created this gist May 30, 2018.
    11 changes: 11 additions & 0 deletions get-apache-namevhost-alias-to-configs.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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 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
    ```