Last active
January 11, 2017 22:11
-
-
Save kvaps/3dabf0aaec05af647568523002285dda to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # Wait for file | |
| until [ -f "$1" ]; do sleep 5 ; 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