对于以下脚本,expect语言中的if块不起作用:
#!/usr/bin/expect -f
set timeout -10
set prompt {$}
spawn ssh 1.1.1.1
expect -re "$prompt"
send -- "echo 12\r"
expect {
"12" {send "echo hunky-dory\r"}
"bg" {send "echo 1\r"}
"ih" {send "echo 2\r"}
}
send -- "exit\r"
interact代码将回显12。但是,它不遵守if块,因此在回显12之后不会回显错误,正如我的脚本所明确指出的那样。
使用#!/usr/bin/expect -d输出
expect version 5.45
argv[0] = /usr/bin/expect argv[1] = -d argv[2] = ./testexpect.exp
set argc 0
set argv0 "./testexpect.exp"
set argv ""
executing commands from command file ./testexpect.exp
spawn ssh <hidden for security reasons>
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {3920}
send: sending "echo 12\r" to { exp4 }
expect: timed out
send: sending "exit\r" to { exp4 }
tty_raw_noecho: was raw = 0 echo = 1
spawn id exp4 sent <echo 12\r\nexit\r\n>
echo 12
exit我的expect块甚至不能被识别。
发布于 2019-10-16 23:57:02
你的问题是:
set timeout -10expect将该负值视为零。实际上,没有为expect块分配执行的时间,您可以直接转到send exit
使用-1或大于零的某个值作为超时值。
https://stackoverflow.com/questions/58403234
复制相似问题