X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=chost;h=204637b003852d21d7c661b966f41e9a69d73ae5;hb=ceeb4e46d3bb326d01fcc7ed98d94ab0b580eda3;hp=77e17d467b3447468c59b832efbd3da893e59b06;hpb=1885f9677fdf2bfeac95285cf13a7d60273d096a;p=automated-distro-installer diff --git a/chost b/chost index 77e17d4..204637b 100755 --- a/chost +++ b/chost @@ -7,6 +7,17 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR host=$1 -addr=$(getent hosts $host | awk '{print $1}') -h=$(getent hosts $addr | awk '{print $2}') -echo ${h%%.*} +# ||: 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##* } +# trailing dot in a hostname will mess up rsync +h=${h%.} +echo $h