X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=chost;h=204637b003852d21d7c661b966f41e9a69d73ae5;hb=14f283f82afc48d6cec1bb7498ec34ac2b0da77c;hp=616874151a0aa5c087c1c275198eb4134cbc530e;hpb=a027429011d313e0d9156fef9451f5a55a588163;p=automated-distro-installer diff --git a/chost b/chost index 6168741..204637b 100755 --- a/chost +++ b/chost @@ -7,7 +7,17 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR host=$1 -addr=$(host $host | sed -rn 's/^\S+ has address //p;T;q') +# ||: 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