-
Notifications
You must be signed in to change notification settings - Fork 0
/
chhost.sh
31 lines (25 loc) · 927 Bytes
/
chhost.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
##############################################################
# Script description -scubamuc- https://scubamuc.github.io/ #
##############################################################
# change host name
# current host name is $hostn
hostn=$(cat /etc/hostname)
# display current host name
echo "Your current hostname is: $hostn"
# request new hostname $newhost
echo "Enter your new hostname: "
echo ""
read newhost
# add new host name in /etc/hosts & /etc/hostname
sudo sed -i "s/$hostn/$newhost/g" /etc/hosts
sudo sed -i "s/$hostn/$newhost/g" /etc/hostname
# display new host name
echo "Your new host name is $newhost"
# confirm new host name
read -s -n 1 -p "Press any key to confirm new host name"
sudo hostname -F /etc/hostname
# restart system if required
read -p " Enter to reboot... Crtl+c to return --> relogin to confirm changes."
##read -s -n 1 -p "Press any key to reboot system"
sudo reboot