Created
December 5, 2018 12:37
-
-
Save andmax/5816fbf5573fe59288e37e243b597817 to your computer and use it in GitHub Desktop.
Bash script to change host name
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
#!/usr/bin/env bash | |
NEW_HOSTNAME=$1 | |
echo $NEW_HOSTNAME > /proc/sys/kernel/hostname | |
sed -i 's/127.0.1.1.*/127.0.1.1\t'"$NEW_HOSTNAME"'/g' /etc/hosts | |
echo $NEW_HOSTNAME > /etc/hostname | |
service hostname start | |
su $SUDO_USER -c "xauth add $(xauth list | sed 's/^.*\//'"$NEW_HOSTNAME"'\//g' | awk 'NR==1 {sub($1,"\"&\""); print}')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment