ssh免密配置种子脚本-ip映射

set timeout 60
spawn ssh root@master
expect {
#首次连接
 "(yes/no)?"  {send "yes\r";exp_continue}
"password"  {send  "root\r"}
}
expect "~]#" {send "echo 192.168.93.128 master >> /etc/hosts \r"}
expect "~]#" {send "echo 192.168.93.129 slaver1 >> /etc/hosts \r"}
expect "~]#" {send "echo 192.168.93.130 slaver2 >> /etc/hosts \r"}
expect "~]#" {send "exit \r"}
#结束expect程序
expect eof


set timeout 60
spawn ssh root@slaver1 
expect {
#首次连接
 "(yes/no)?"  {send "yes\r";exp_continue}
"password"  {send  "root\r"}
}
expect "~]#" {send "echo 192.168.93.128 master >> /etc/hosts \r"}
expect "~]#" {send "echo 192.168.93.129 slaver1 >> /etc/hosts \r"}
expect "~]#" {send "echo 192.168.93.130 slaver2 >> /etc/hosts \r"}
expect "~]#" {send "exit \r"}
#结束expect程序
expect eof

set timeout 60
spawn ssh root@slaver2 
expect {
#首次连接
 "(yes/no)?"  {send "yes\r";exp_continue}
"password"  {send  "root\r"}
}
expect "~]#" {send "echo 192.168.93.128 master >> /etc/hosts \r"}
expect "~]#" {send "echo 192.168.93.129 slaver1 >> /etc/hosts \r"}
expect "~]#" {send "echo 192.168.93.130 slaver2 >> /etc/hosts \r"}
expect "~]#" {send "exit \r"}
#结束expect程序
expect eof
posted @ 2024-11-22 14:38  基础狗  阅读(4)  评论(0编辑  收藏  举报