Skip to content
Snippets Groups Projects
Commit f105dbba authored by Pete Tucker's avatar Pete Tucker
Browse files

modify hostname.sh to add 127.0.0.0 entry to /etc/hosts if not already present

parent 353217ef
No related branches found
No related tags found
No related merge requests found
......@@ -70,3 +70,15 @@ else
# unit serial number set, use it
hostname $(get_sn 37).$url
fi
#Add 127.0.0.0 entry to /etc/hosts if it is not already present
grep "127.0.0.0" /etc/hosts > tmp/junk
if [ -s /tmp/junk ]; then
rm /tmp/junk
else
NAME=$(hostname)
SHORTNAME=$(hostname | cut -b -16)
NEWLINE="127.0.0.0 $NAME $SHORTNAME"
sed -e"/^127.0.0.1/a ${NEWLINE}" /etc/hosts > /tmp/hosts2
  • Owner

    replacing this with sed -i "/^127.0.0.1/a ${NEWLINE}" /etc/hosts

    will edit the file inline, so you won't need to create hosts2 and then move it.

    Edited by David Mondou
  • Please register or sign in to reply
mv /tmp/hosts2 /etc/hosts
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment