Linux 有没有一种方法可以;期望;及;“发送”;“之后”;“互动”;命令
因此,我需要在stdout上输出远程进程,但我还需要能够“侦听”它,并在匹配关键字后发送命令 我需要这样的东西(我知道这个代码是不正确的,它的唯一目的是说明我需要什么)Linux 有没有一种方法可以;期望;及;“发送”;“之后”;“互动”;命令,linux,shell,tcl,expect,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"} inte
如果我没记错的话,你可以这样做:
#!/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
}
}
您将要注意的事情和要采取的行动作为参数传递给
交互
(与expect
)并在最后告诉响应脚本要exp\u continue
,以便它继续交互/期望。令人惊讶的是,这个答案被接受,显然,问题是希望程序发送mykeyword
,并希望向程序发送\003\177\015
,就像用户键入的一样。此答案等待用户键入mykeyword
。在模式产生预期行为之前添加-o
:-o interact{“mykeyword”
。
#!/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
}
}