Skip to content

Instantly share code, notes, and snippets.

@pixmin
Last active January 30, 2020 11:33
Show Gist options
  • Save pixmin/ad534c873e1bebc699ca81e47c764f59 to your computer and use it in GitHub Desktop.
Save pixmin/ad534c873e1bebc699ca81e47c764f59 to your computer and use it in GitHub Desktop.
Get a list of domains on a server
#!/bin/bash
# From all the Apache sites-enabled conf files,
# extract the ServerAlias and ServerName lines.
# And for nginx too.
find /etc/apache2/sites-enabled/ -name "*.conf" -exec grep -E "ServerName|ServerAlias" {} \; \
| grep -vE '^*\#' | sed -e 's/^[ \t]*//' | grep --color -E "^|ServerName|ServerAlias" \
| awk {'print $2'} | sort | uniq
find /etc/nginx/sites-enabled/ -type l -exec grep -E "server_name" {} \; \
| grep -vE '^*\#' | sed -e 's/^[ \t]*//' | grep --color -E "^|server_name" \
| awk {'print $2'} | sort | uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment