Yes you can.
Try launching it from expect, or using an expect module for your favorite scripting language. I do this all the time in python, and in regular tcl/expect.
#!/usr/bin/python
import pexpect, sys, time, re
SSH_NEWKEY = 'Are you sure you want to continue connecting'
ssh = pexpect.spawn('ssh user-name@%s'%(host))
retval = ssh.expect([SSH_NEWKEY, '[Pp]assword:', pexpect.EOF, pexpect.TIMEOUT]
, timeout = TIMEOUT)
time.sleep(1)
if retval == 0:
ssh.sendline ('yes')
i = ssh.expect(['[Pp]assword: ', pexpect.EOF, pexpect.TIMEOUT], timeout = TIMEOUT)
time.sleep(1)
if i > 0:
.....
OR
#!/usr/bin/expect
......
proc myconnect { ip pass enable } {
if { $ip != "" } {
spawn ssh admin@$ip
expect_before {
"Connection closed by $ip" {
catch { close -i $spawn_id }
return 0
}
}
expect {
# anticipate connection issues along the way and not get hung up
timeout {
return 0
}
"Connection refused" {
return 0
}
"Are you sure you want to continue connecting" {
send "yes\r"
exp_continue
}
"Do you want to change the host key on disk" {
send "yes\r"
exp_continue
}
.......