我有这个简单的期望脚本,它发送一个命令并等待响应,只有一些行匹配。
#!/usr/bin/expect -f
log_user 0
send "user --all\r"
expect {
timeout { send_user "\nTimeout during command\n"; exp_continue }
-re "OK OK OK STARTED" { send_user "$expect_out(0,string)\n"; append dbscntl $expect_out(buffer); exp_continue }
-re "Succeess!" { exp_continue }
-re ">"
}
exit 0
如何在正则表达式行中send_out与正则表达式匹配的整行“OK OK OK STARTED”。
在我的send_user "$expect_out(0,string)\n";
代码中,只给出了匹配的正则表达式“OK OK OK STARTED”而不是整行。
与正则表达式匹配的行的示例:
0 Running site1 OK OK OK STARTED
1 Panding site1 OK OK OK STARTED
2 Running site1 OK OK - STARTED
3 Stopped site1 - OK OK STARTED
现在我会得到:
OK OK OK STARTED
OK OK OK STARTED
但我会错过第二栏的信息。
所以,我想要像:
0 Running site1 OK OK OK STARTED
1 Panding site1 OK OK OK STARTED
谢谢!
答案 0 :(得分:0)
在建议和一些尝试之后,我发现这在我的案例-re "(?n)^DSG.*OK OK OK STARTED(.*)" { send_user "$expect_out(0,string)\n"; append dbscntl $expect_out(buffer); exp_continue }
中有效。
基本上,我有两个问题: