expect: spawn id exp4 not open原因解释

脚本:

#! /bin/bash

auto_send(){
/usr/bin/expect <

运行脚本时报错:

$ sh auto_send.sh 
spawn scp test.sh [email protected]:~
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

你可能感兴趣的:(Linux,shell脚本)