我只是有一个更大的bash脚本在那里我偶然发现一个问题,使用ssh连接到另一台计算机。这是第一次访问(总是,真的;)),因此要求主机的真实性[192.168.120.170]:9022([192.168.120.170]:9022)''不能建立。 您确定要继续连接(是/否)吗?spawn:如何传递参数在期望脚本中产生?
所以我试着用额外的 expect/spawn脚本来回答这个问题。
所以,我有两个文件: deploy.sh
#!/bin/bash
... Some functions and more
# call expect script to get a first time onto the target
/usr/bin/expect -d -f ./deployImage_helper.exp -- -p 9022 [email protected]
deploy_helper.exp
#!/usr/bin/env expect -f
set args [lrange $argv 1 end]
spawn ssh {*}$args
expect "The authenticity of host'[192.168.120.170]([192.168.120.170]:9022)' can't be established."
send "yes"
如果我运行deploy.sh我得到的错误信息:无效的命令名称“192.168.120.170”
不知何故,我不会产卵运行ssh。
任何帮助,将不胜感激。
编辑:
更改deploy.sh线4
'希望-d -f deploy_helper.exp - 192.168.120.170 -p 9022',看看什么是错的。 – pynexj
我添加了调试输出并更新了上面的编辑。输出是:** argv [0] =/usr/bin/expect argv [1] = -d argv [2] = -f argv [3] = ./deployImage_helper.exp argv [4] = - argv [ 5] = -p argv [6] = 9022 argv [7] = [email protected] set argc 3 set argv0“./deployImage_helper.exp” set argv“-p 9022 [email protected]” 正在执行从命令文件./deployImage_helper.exp 产卵的ssh -p 9022 [email protected]命令 父:等同步字节 父:告诉孩子先走 父:现在从儿童 产卵不同步:返回{6570} * * –