我有下面的expect脚本,如果不存在已知的主机,它将添加一个已知的主机。
#!/usr/bin/expect
spawn ssh user@domain "cd /home/user"
expect "Are you sure you want to continue connecting (yes/no)?"
send "yes\r"
interact当我第一次将ssh放入设备时,脚本工作得很好,但是如果我将ssh插入设备n+1,则会引发一个错误。
send: spawn id exp6 not open
while executing
"send "yes\r""
(file "./testing_spawn.sh" line 4)大概是因为它继续期望字符串Are you sure you want to continue connecting (yes/no)?
如果没有显示消息,我如何告诉脚本只显示interact?
发布于 2015-03-20 15:22:51
只有当“未知主机”问题出现在命令提示符之前时,才使用expect_before:
#!/usr/bin/expect
spawn ssh user@domain
expect_before "*(yes/no)?" {
send "yes\r"
}
expect "*# "
interacthttps://serverfault.com/questions/489903
复制相似问题