【发布时间】:2017-09-02 19:59:51
【问题描述】:
我只是有一个更大的 bash-script,我偶然发现了一个问题,使用 ssh 连接到另一台计算机。那是第一次访问(总是,真的;)),因此询问主机'[192.168.120.170]:9022([192.168.120.170]:9022)'的真实性无法建立。 确定要继续连接(是/否)?
所以我尝试使用 additional 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 root@192.168.120.170
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,我会收到错误消息:invalid command name "192.168.120.170"
不知怎的,我没有让 spawn 运行 ssh。
任何帮助将不胜感激。
编辑:
更改了 deploy.sh 第 4 行
【问题讨论】:
-
expect -d -f deploy_helper.exp -- 192.168.120.170 -p 9022看看有什么问题。 -
我添加了调试输出并更新了上面的 EDIT。输出为: 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] = root@192.168.120.170 set argc 3 set argv0 "./deployImage_helper.exp" set argv "-p 9022 root@192.168.120.170" 从命令执行命令文件 ./deployImage_helper.exp spawn ssh -p 9022 root@192.168.120.170 父:等待同步字节 父:告诉子继续 父:现在与子生成不同步:返回 {6570}
标签: linux bash ssh parameter-passing expect