iankelling.org
/
git
/
automated-distro-installer
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
more complete copyright notices
[automated-distro-installer]
/
chost
diff --git
a/chost
b/chost
index 3e1acd216f8cf5fe055641021c95844f7f53b070..204637b003852d21d7c661b966f41e9a69d73ae5 100755
(executable)
--- a/
chost
+++ b/
chost
@@
-7,7
+7,17
@@
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
host=$1
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
host=$1
-addr=$(host $host | sed -rn 's/^.*has address (.*)/\1/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)
h=$(host $addr)
+case $h in
+ *"no PTR record")
+ echo "error: chost: $h" >&2
+ exit 1
+ ;;
+esac
h=${h##* }
h=${h##* }
-echo ${h%%.*}
+# trailing dot in a hostname will mess up rsync
+h=${h%.}
+echo $h