From 903e6a63f8f16f3baef0d8e47d8045ccaa1783cc Mon Sep 17 00:00:00 2001 From: Joe Cooper Date: Wed, 23 Aug 2017 16:52:02 -0500 Subject: [PATCH] Set shortname in the right scope --- slib.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/slib.sh b/slib.sh index 540a385..eba843a 100644 --- a/slib.sh +++ b/slib.sh @@ -473,15 +473,14 @@ set_hostname () { else hostname "$line" detect_ip + shortname=$(echo "$line" | cut -d"." -f1) if grep "$address" /etc/hosts; then log_debug "Entry for IP $address exists in /etc/hosts." log_debug "Updating with new hostname." - shortname=$(echo "$line" | cut -d"." -f1) sed -i "s/^$address\([\s\t]+\).*$/$address\1$line\t$shortname/" /etc/hosts else log_debug "Adding new entry for hostname $line on $address to /etc/hosts." - printf "%s\t%s\t%s\n" \ - "$address" "$line" "$shortname" >> /etc/hosts + printf "%s\t%s\t%s\n" "$address" "$line" "$shortname" >> /etc/hosts fi i=1 fi