Created
January 5, 2017 23:21
-
-
Save kvaps/f0f5b82069776cc0d270a450d8c96325 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REPEAT=120 #2 minutes | |
# Wait for file | |
until [ -f "$1" ]; do | |
sleep 1 | |
# Timeout check | |
if [ "$REPEAT" -gt 0 ]; then | |
((REPEAT--)) | |
else | |
exit 1 | |
fi | |
done | |
# Remove exist hostname | |
sed -i '/ '$(hostname)'$/d' "$1" 2> /dev/null | |
# Write new hostname | |
echo "$(ip addr list | grep -oP '(?<=inet )([0-9]+.){3}[0-9]+' | tail -n1) $(hostname)" >> "$1" | |
# replace default hosts-file | |
rm -f /etc/hosts | |
ln -s "$1" /etc/hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment