【发布时间】:2023-03-09 08:37:01
【问题描述】:
我有一个监控 IBMIHS 服务器上的 http pid 的 EXPECT 脚本:
....
send "ps -ef|grep htt|grep start|wc -l \r"
expect {
-re {.*(\d+).*} {
set theNum $expect_out(1,string)
}
}
puts "theNum = $theNum"
if {$theNum > 8} {
puts "it is ok"
} else {
puts "it is not ok"
}
....
send "ps -ef|grep htt|grep start|wc -l \r" 生成:
发送:发送“ps -ef|grep htt|grep start|wc -l \r”到{ exp5 }
Gate '.(\d+).' 的 keeper glob 模式是 ''。不可用,禁用 性能助推器。期望:“” (spawn_id exp5) 是否匹配正则表达式“.(\d+).”? (无门,仅限 RE)gate=yes re=no
ps -ef|grep htt|grep start|wc -l期望:"ps -ef|grep htt|grep start|wc -l \r\n" (spawn_id exp5) 匹配正则表达式“.(\d+).”? (无门,仅 RE)门=是 re=no
11期望:“ps -ef|grep htt|grep start|wc -l \r\n11\r\n”(spawn_id exp5) 匹配正则表达式“.(\d+).”? (无门,仅限 RE) 门=是 重新=是
expect: set expect_out(0,string) "ps -ef|grep htt|grep start|wc -l \r\n11\r\n"
expect: set expect_out(1,string) "1"
期望:设置 期望输出(spawn_id)“exp5”期望:设置期望输出(缓冲区)“ps -ef|grep htt|grep start|wc -l \r\n11\r\n"
theNum = 1
不行
命令行实际上返回一个数字“11”,但(\d+) 却捕获了一个'1'。
提前感谢您的 cmets。
【问题讨论】: