期待脚本如何检查条件

时间:2017-01-17 16:52:00

标签: expect

有没有办法用循环检查每个期望条件并且有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

1 个答案:

答案 0 :(得分:2)

if-elsif中的expect条件类似于下面的情况。对于这两种情况,你实际上是在做同样的动作,但这是如何完成的。

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