revert chost, broke for localhost
authorIan Kelling <ian@iankelling.org>
Mon, 10 Apr 2017 05:11:53 +0000 (22:11 -0700)
committerIan Kelling <ian@iankelling.org>
Mon, 10 Apr 2017 05:11:53 +0000 (22:11 -0700)
chost

diff --git a/chost b/chost
index 77e17d467b3447468c59b832efbd3da893e59b06..3e1acd216f8cf5fe055641021c95844f7f53b070 100755 (executable)
--- a/chost
+++ b/chost
@@ -7,6 +7,7 @@ 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}')
+addr=$(host $host | sed -rn 's/^.*has address (.*)/\1/p;T;q')
+h=$(host $addr)
+h=${h##* }
 echo ${h%%.*}