脚本:
#! /bin/bash
auto_send(){
/usr/bin/expect <<EOF
set timeout 10
spawn scp test.sh xxxx@10.201.7.189:~
expect {
"yes/no" { send "yes\r";exp_continue }
"password" {send "VMUSi\r"}
}
expect eof
EOF
}
auto_send
运行脚本时报错:
$ sh auto_send.sh
spawn scp test.sh testhadoop@10.201.7.189:~
test.sh 100% 223 0.2KB/s 00:00
expect: spawn id exp4 not open
while executing
"expect eof"
原因:
生成了ssh公钥,并拷贝到了目标机器上,因此,没有等到expect eof是,ssh连接已经关闭了。
删掉目标机器上的公钥即可。但是不删除的话,每次运行还会出现这个报错,暂时没有搜到更好的解决办法。
参考:
https://blog.csdn.net/zhaoyangjian724/article/details/25367515
https://stackoverflow.com/questions/1387848/issues-with-expect-send-spawn-id-exp4-not-open