关于expect脚本的一个小问题

脚本内容为:

#!/usr/bin/expect
set timeout -1
spawn scp /data/aaa_557_data.tar root@10.66.1.43:/data/
expect {
    "password" {send "abc123\n";}
    "yes/no" {send "yes";exp_continue}
}
interact

 

执行脚本:

/usr/bin/expect aa.exp

 

报错信息为:

spawn scp /data/aa_557_data.tar root@10.66.1.43:/data/

Warning: Permanently added '10.66.1.43' (RSA) to the list of known hosts.

aa_557_data.tar                                                   100% 389MB 129.6MB/s 00:03

spawn_id: spawn id exp4 not open

    while executing

"interact"

    (file "scp_script.ex" line 8)

 

报错原因:因为源机器能免密码登录目标机器,而上面的脚本中,是需要询问密码且回答yes或no才能登录的,

所以执行脚本时,导致了错误。

修复办法:删除目标机器中~/.ssh/authorized_keys中的关于源机器的信息。

 

posted @ 2021-10-12 17:30  道霖  阅读(252)  评论(0编辑  收藏  举报