I just have a bigger bash-script where I stumbled into a problem, to use ssh to connect to another computer. That one is visited first time (always, really ;) ) and therefore asks The authenticity of host '[192.168.120.170]:9022 ([192.168.120.170]:9022)' can't be established. Are you sure you want to continue connecting (yes/no)?
So I tried to answer this question using an additional expect/spawn script.
So I have two files: 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"
If I run deploy.sh I get the error message: invalid command name "192.168.120.170"
Somehow I don't get spawn running ssh .
Any help would be appreciated.
EDIT:
Changed deploy.sh line 4
set args [lrange $argv 1 end]
spawn ssh {*}$args
expect -re {The authenticity of .* can't be established.} {
send "yes"
}
interact
Inside ""
variables and square brakets []
(evaluate command inside brackets and place result instead), will be expanded and evaluated. You need quote square brackets \\[
or use {}
instead of ""
. BTW, you can supress asking this question (only warning showing) by openssh options:
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 9022 root@192.168.120.170
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.