小编gue*_*_90的帖子

生成:如何在期望脚本中将参数传递给生成?

我只是有一个更大的bash 脚本,我在其中遇到了一个问题,即使用ssh连接到另一台计算机。该主机是第一次访问(总是,真的;)),因此询问主机 '[192.168.120.170]:9022 ([192.168.120.170]:9022)' 的真实性无法确定。您确定要继续连接吗(是/否)?

所以我尝试使用额外的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
Run Code Online (Sandbox Code Playgroud)

部署助手.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"
Run Code Online (Sandbox Code Playgroud)

如果我运行deploy.sh,我会收到错误消息:invalid command name "192.168.120.170"

不知怎的,我没有让 spawn 运行ssh

任何帮助,将不胜感激。

编辑:

更改了 …

linux ssh bash expect parameter-passing

2
推荐指数
1
解决办法
3801
查看次数

标签 统计

bash ×1

expect ×1

linux ×1

parameter-passing ×1

ssh ×1