#! /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 }"