Skip to content

Instantly share code, notes, and snippets.

@trepidity
Created May 27, 2020 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trepidity/14f5f4671251f1ace62074148a6bff69 to your computer and use it in GitHub Desktop.
Save trepidity/14f5f4671251f1ace62074148a6bff69 to your computer and use it in GitHub Desktop.
set machine hostname (FOR NAM)
echo "Creating host entry..." | tee -a $LOG_OUTPUT
HOST_NAME=`hostname`
IP_ADDR=`ip addr | grep -Po '(?!(inet 127.\d.\d.1))(inet \K(\d{1,3}\.){3}\d{1,3})' | head -n 1`
HOST_PRESENT=`grep $HOST_NAME /etc/hosts`
if [ -z "$HOST_PRESENT" ]
then
echo -e "$IP_ADDR\t$HOST_NAME\t$HOST_NAME" >> /etc/hosts
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment