im using this script to change hostname via ssh but i got some errors.
read -p "Insira o IP : " ip
read -p "Insira o nome do utilizador : " host
read -s -p "Insira a palavra passe : " oldpass
sshpass -p $oldpass ssh $host@$ip "cat /etc/hostname > hostname.txt"\
run="sshpass -p $oldpass ssh $host@$ip" \
hostn=$($run "cat hostname.txt") \
echo $hostn
sshpass -p $oldpass ssh $host@$ip " \
echo "Enter new hostname: " \
read newhost \
sed -i "s/$hostn/$newhost/g" /etc/hosts \
sed -i "s/$hostn/$newhost/g" /etc/hostname \
echo "Your new hostname is "$newhost"" \
read -s -n 1 -p "Press any key to reboot" \
reboot"
When i write new hostname appear that:
unable to resolve host"=.
But the script continued work and do reboot.
$oldpassin never properly quoted. Also, backslashes will not be read correctly as you're not using-rwithread. In general, your script is a quoting minefield.;. Otherwise you'll be trying to executeecho something read newhost sed ...etc. as a single command.