Skip to content

Instantly share code, notes, and snippets.

@ymauray
Last active February 26, 2021 09:35
Show Gist options
  • Save ymauray/93009a2d457a37511f1413f59906b013 to your computer and use it in GitHub Desktop.
Save ymauray/93009a2d457a37511f1413f59906b013 to your computer and use it in GitHub Desktop.
Get a list of "server_name" an nginx server knows about (FreeBSD version, using gsed)
#!/bin/bash
sudo nginx -T 2>/dev/null \
| gsed -r -e 's/[[:space:]]*$//' -e 's/^[[:space:]]*//' -e 's/^#.*$//' -e 's/[[:space:]]*#.*$//' -e '/^$/d' \
| gsed -e ':a;N;$!ba;s/\([^;\{\}]\)\n/\1 /g' \
| grep 'server_name[[:space:]]' \
| grep -v '\$' \
| grep '\.' \
| gsed -r -e 's/(\S)[[:space:]]+(\S)/\1\n\2/g' -e 's/;//' \
| grep -v "^server_name$" \
| grep -v "^$" \
| sort \
| uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment