diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/get_catalog | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/bin/get_catalog b/bin/get_catalog new file mode 100755 index 0000000..d9e744b --- /dev/null +++ b/bin/get_catalog @@ -0,0 +1,41 @@ +#! /bin/sh +# +# Fetch the catalog zone '$1' from the server '$2' and print a list of zones. + +set -e + +catalog="$1" +server="$2" + +tempfile="$(mktemp -t catalog)" +trap 'rm $tempfile' 0 + +if ! dig "$catalog" axfr @"$server" +noall +answer >"$tempfile"; then + printf >&2 '%s: query failed\n' "$0" + exit 1 +fi + +# Make sure the result has an SOA, otherwise the query failed. +if ! awk <"$tempfile" " +BEGIN { + exitcode=1 +} + +\$1 == \"$catalog.\" && \$4 == \"SOA\" { + exitcode=0 +} + +END { + exit exitcode +} +"; then + printf >&2 '%s: no SOA found in zone; transfer failed?\n' "$0" + exit 1 +fi + +awk <"$tempfile" " +\$1 ~ /zones.$catalog/ && \$4 == \"PTR\" { + zone = \$5 + sub(/\\.$/, \"\", zone) + print zone +}" |
