有没有办法在 TCL 中 IF CONDITION a expect 语句?
Is there a way to IF CONDITION a expect statement in TCL?
有什么方法可以 IF CONDITION an expect 命令。例如在下面的代码中,我试图通过 ssh 连接到一个特定的 IP 地址,有时它会询问我 "Are you sure you want to continue connecting (yes/no)?" 有时它不会。我如何做到 IF 它显示我发送 "yes/r" 而 IF 它不显示,我继续我的代码?
set name="123.456.78.910"
expect "$ " ; send -- "ssh root@$name\r"
expect {
"Password:" { send "password" }
timeout { sleep 1 }
}
expect "Are you sure you want to continue connecting (yes/no)?" ; send -- "yes\r”
这是 exp_continue
命令的目的:
spawn ssh user@host
set prompt {$ $} ;# or whatever regex your prompt matches
expect {
timeout {error "timed out connecting to host"}
"continue connecting" {send "yes\r"; exp_continue}
"Password:" {send "$password\r"; exp_continue}
-re $prompt
}
send "do stuff\r"
# ...
如果预期超时,则脚本错误。
如果您收到 "continue connecting" 提示,请发送 "yes" 并继续期待。
如果您收到 "Password" 提示,请发送您的密码并继续等待。
当 收到 shell 提示时,expect
命令完成,您可以继续执行程序。
有什么方法可以 IF CONDITION an expect 命令。例如在下面的代码中,我试图通过 ssh 连接到一个特定的 IP 地址,有时它会询问我 "Are you sure you want to continue connecting (yes/no)?" 有时它不会。我如何做到 IF 它显示我发送 "yes/r" 而 IF 它不显示,我继续我的代码?
set name="123.456.78.910"
expect "$ " ; send -- "ssh root@$name\r"
expect {
"Password:" { send "password" }
timeout { sleep 1 }
}
expect "Are you sure you want to continue connecting (yes/no)?" ; send -- "yes\r”
这是 exp_continue
命令的目的:
spawn ssh user@host
set prompt {$ $} ;# or whatever regex your prompt matches
expect {
timeout {error "timed out connecting to host"}
"continue connecting" {send "yes\r"; exp_continue}
"Password:" {send "$password\r"; exp_continue}
-re $prompt
}
send "do stuff\r"
# ...
如果预期超时,则脚本错误。
如果您收到 "continue connecting" 提示,请发送 "yes" 并继续期待。
如果您收到 "Password" 提示,请发送您的密码并继续等待。
当 收到 shell 提示时,expect
命令完成,您可以继续执行程序。