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