X-Git-Url: https://iankelling.org/git/?p=automated-distro-installer;a=blobdiff_plain;f=chost;h=a26529fee9efbeaf3a14632946d59d4e84d7bc8d;hp=9fa57d07db3e997ab955db6dfa6a12ca3327a81d;hb=HEAD;hpb=1a5548031efc4a1fa88ca94237eac3033cf97ef1 diff --git a/chost b/chost index 9fa57d0..204637b 100755 --- a/chost +++ b/chost @@ -7,8 +7,17 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR host=$1 -addr=$(host $host) -addr=${addr##* } +# ||: because if we are using 2+ resolvers, 1 may fail, causing error, but we still get +# a valid address and we just use that +addr=$(host $host | sed -rn 's/^\S+ has address //p;T;q' ||:) h=$(host $addr) +case $h in + *"no PTR record") + echo "error: chost: $h" >&2 + exit 1 + ;; +esac h=${h##* } -echo ${h%%.*} +# trailing dot in a hostname will mess up rsync +h=${h%.} +echo $h