X-Git-Url: https://iankelling.org/git/?p=automated-distro-installer;a=blobdiff_plain;f=chost;h=18c0aacb1f0ec73f2ca956efa1aa12bb4f93be99;hp=9a0034f120db7e94ee0377f4f5b98c27ea19f4ce;hb=1b08e82a978c8db76e1ebc67f3b4ae875ba27537;hpb=afabe0c27af744200aa6b6e05c5b2ab7d7518c1e diff --git a/chost b/chost index 9a0034f..18c0aac 100755 --- a/chost +++ b/chost @@ -1,4 +1,5 @@ #!/bin/bash +# Copyright (C) 2016 Ian Kelling # chost: get canonical hostname @@ -6,8 +7,15 @@ 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%%.*} +echo $h