我想自动化ssh登录。经过一番研究,似乎tcl/expect是要走的路线。自动化ssh登录:tcl expect交互命令行为怪异
但是,我的问题是,当交互接管我的终端,东西不能按预期工作(双关语不是预期的)。
例如,如果我调整终端大小,它不会“取”。另外,有时互动不响应,有时它只是无缘无故地挂起。我在下面列出了我的代码。我的代码问题是,我错过了什么?
另外,有没有更好的方法来做到这一点(与另一种脚本语言?)我需要终端非常灵敏,没有比在手持式控制台上手动键入ssh没有什么不同。
proc Login {username server password} {
set prompt "(%|>|\#|\\\$) $"
spawn /usr/bin/ssh [email protected]$server
expect {
-re "Are you sure you want to continue connecting (yes/no)?" {
exp_send "yes\r"
exp_continue
#continue to match statements within this expect {}
}
-nocase "password: " {
exp_send "$password\r"
interact
}
}
}
大概你不能使用'ssh-keygen'生成认证的RSA/DSA密钥? – 2010-07-21 18:39:20