Last active
November 3, 2020 13:03
-
-
Save imneonizer/28ea572b719b394c4e1867fe334c3d73 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
# Check if sudo permission is available, else exit | |
if [ `id -u` != "0" ] | |
then | |
echo '[ERROR] please run with sudo' | |
exit | |
fi | |
# Retrieve new hostname from args | |
if [ -z "$1" ] | |
then | |
echo "usage: $0 HOSTNAME" | |
else | |
# Assign existing hostname to $hostn | |
hostn=$(cat /etc/hostname); newhost=$1 | |
echo "[INFO] updating '$hostn' > '$1'" | |
sed -i "s/$hostn/$newhost/g" /etc/hosts | |
sed -i "s/$hostn/$newhost/g" /etc/hostname | |
hostnamectl set-hostname $newhost | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment