Skip to content

Instantly share code, notes, and snippets.

@jcppkkk
Created July 31, 2017 18:21
Show Gist options
  • Save jcppkkk/7741f2fedfd718fbdf6b96e8329678e2 to your computer and use it in GitHub Desktop.
Save jcppkkk/7741f2fedfd718fbdf6b96e8329678e2 to your computer and use it in GitHub Desktop.
#!/bin/bash
old=`hostname`
new="$1"
read -p "Change hostname from \"$old\" to \"$new\"? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
sudo true
set -v
sudo hostnamectl set-hostname $new
sudo sed -i"" "s#$old#$new#" /etc/hosts
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment