我只是有一個更大的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} * * –