期望脚本如何检查条件

expect script how to check for conditions

有没有办法用循环检查每个预期条件并有 if 语句?

#!/usr/bin/expect
spawn telnet 10.10.10.10
set timeout 200000000
expect "login"
send "user\r"
expect "Password:"
send "password\r"
send "./run/this.sh\r"
/* 
Here is where I'm confused 
*/

if[ "expect" = "close" ] 
then
    send "exit\r"
elif[ "expect" = "end" ] 
    send "exit\r"
fi

expect 中的 if-elsif 条件与您的案例类似。您实际上是在对这两种情况执行相同的操作,但这是如何完成的。

expect {
  "close" {
    send "exit\r"
  }
  "end" {
    send "exit\r"
  }
}