有没有办法用循环检查每个期望条件并且有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
答案 0 :(得分:2)
if-elsif
中的expect
条件类似于下面的情况。对于这两种情况,你实际上是在做同样的动作,但这是如何完成的。
expect {
"close" {
send "exit\r"
}
"end" {
send "exit\r"
}
}