ip.sh
ips="i172.16.11.65"
在此操作之前应该先通过ssh-keygen -t rsa生成密钥
设置信任关系,机器B的用户为userB,密码是www,机器A的用户为userA
set_auth.sh
#! /bin/bash
source ./ip.sh
for ip in $ips
do
{
expect -c "spawn scp -r /home/userA/.ssh/id_rsa.pub userB@$ip:~/.ssh/authorized_keys
expect {
\"*(yes/no)?\" {
send \"yes\r\";
expect \"*assword:\" {
send \"www\r\"
}
}
\"*assword:\" {
send \"www\r\";
send \"exit\r\"
}
}
expect eof
interact
"
echo "$ip is finish"
sleep 3
}
done
修改hosts中的ip地址192.168.1.178为ips.sh文件中ip地址
change_ip.sh
#! /bin/bash
source ./ip.sh
for ip in $ips
do
{
ssh -t oracle@$ip "sudo sed -i 's/192.168.1.178/$ip/g' /etc/hosts < /dev/null"
echo "$ip hosts is change"
sleep 3
}
done