Last active
February 26, 2021 09:35
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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