Skip to content

Commit

Permalink
Set shortname in the right scope
Browse files Browse the repository at this point in the history
  • Loading branch information
swelljoe committed Aug 23, 2017
1 parent 9497bdc commit 903e6a6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions slib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 903e6a6

Please sign in to comment.