Created
June 24, 2014 15:54
-
-
Save chales/80d25a47427c5a7eb6b8 to your computer and use it in GitHub Desktop.
Set ubuntu hostname via script using sed
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 | |
# Set $chostname to current hostname | |
chostname=$(cat /etc/hostname) | |
# Display current hostname | |
echo "Current hostname is '$chostname'" | |
# Set $newhostname as new hostname | |
echo "Enter new hostname: " | |
read newhostname | |
# Change the hostname value in /etc/hostname and /etc/hosts files | |
sudo sed -i "s/$chostname/$newhostname/g" /etc/hostname | |
sudo sed -i "s/$chostname/$newhostname/g" /etc/hosts | |
# Display new hostname | |
echo "Your new hostname is $newhostname" | |
# Reboot the system | |
read -s -n 1 -p "Press any key to reboot!" | |
sudo reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment