Hostname: differenze tra le versioni
Da PNLUG.
(Creata pagina con "=Questo piccolo script rendere facile ed interattivo il cambio del hostname= ==Debian Like== #!/bin/bash #Assign existing hostname to $hostn hostn=$(cat /etc/hostname)...") |
(→Debian Like) |
||
| (Una versione intermedia di uno stesso utente non è mostrata) | |||
| Riga 4: | Riga 4: | ||
#!/bin/bash | #!/bin/bash | ||
| − | + | # | |
#Assign existing hostname to $hostn | #Assign existing hostname to $hostn | ||
hostn=$(cat /etc/hostname) | hostn=$(cat /etc/hostname) | ||
| − | + | # | |
#Display existing hostname | #Display existing hostname | ||
| − | echo "Existing hostname is $hostn" | + | echo "Existing hostname is $hostn" |
| − | + | # | |
#Ask for new hostname $newhost | #Ask for new hostname $newhost | ||
echo "Enter new hostname: " | echo "Enter new hostname: " | ||
read newhost | read newhost | ||
| − | + | # | |
#change hostname in /etc/hosts & /etc/hostname | #change hostname in /etc/hosts & /etc/hostname | ||
sed -i "s/$hostn/$newhost/g" /etc/hosts | sed -i "s/$hostn/$newhost/g" /etc/hosts | ||
sed -i "s/$hostn/$newhost/g" /etc/hostname | sed -i "s/$hostn/$newhost/g" /etc/hostname | ||
| − | + | # | |
#display new hostname | #display new hostname | ||
echo "Your new hostname is $newhost" | echo "Your new hostname is $newhost" | ||
Versione attuale delle 18:42, 29 set 2015
Questo piccolo script rendere facile ed interattivo il cambio del hostname
Debian Like
#!/bin/bash # #Assign existing hostname to $hostn hostn=$(cat /etc/hostname) # #Display existing hostname echo "Existing hostname is $hostn" # #Ask for new hostname $newhost echo "Enter new hostname: " read newhost # #change hostname in /etc/hosts & /etc/hostname sed -i "s/$hostn/$newhost/g" /etc/hosts sed -i "s/$hostn/$newhost/g" /etc/hostname # #display new hostname echo "Your new hostname is $newhost"