有没有办法在"互动"命令后"期待"和"发送"

Eed*_*doh 3 linux shell tcl expect

所以我需要在我的stdout上输出远程进程,但我还需要能够"监听"它,并在匹配我的关键字后发送命令.

我需要这样的东西(我知道这段代码不正确,它的唯一目的是说明我需要的东西)

#!/usr/bin/expect
log_user 0
spawn ssh -o PubkeyAuthentication=no [lindex $argv 0] -n [lindex $argv 1]
expect "Password:" {send "mypassword\r"}
interact
expect "mykeyword" {send "\003\177\015"}
Run Code Online (Sandbox Code Playgroud)

Don*_*ows 7

如果我没记错的话,你这样做:

#!/usr/bin/expect
log_user 0
spawn ssh -o PubkeyAuthentication=no [lindex $argv 0] -n [lindex $argv 1]
expect "Password:" {send "mypassword\r"}
interact {
     "mykeyword" {
         send "\003\177\015"
         exp_continue
     }
}
Run Code Online (Sandbox Code Playgroud)

你传递要注意的事物和作为参数的动作interact(就像用expect),你告诉响应脚本到exp_continue最后,以便它继续交互/期待.