while
ループを削除するためにコードを書き直します。
set number_ok 0
set node_patt "(Reloading configuration on node (\\d+?) \\((\[^)]+?)\\))\r\n(.+?)\r\n"
send "cluster config -r -a\r"
expect {
ERROR {cluster_exit 1}
-re $node_patt {
set line "<$cmdline> $expect_out(1,string)"
set node_num $expect_out(2,string)
set node_name $expect_out(3,string)
set result $expect_out(4,string)
switch -regexp $result {
"Node .+ not found" {
ok 0 "$line (not found)"
}
"Node .+ not responding, skipped" {
ok 0 "$line (not responding)"
}
OK {
ok 1 $line
incr number_ok
}
}
exp_continue ;# loop back to top of expect block
}
$ROOT_PROMPT ;# no action, so fall out of the expect block
}
Tcl 正規表現は、完全に貪欲であるか、完全に非貪欲であることに注意してください。\r\n(.+)\r\n
「ノードで設定をリロードしています...」に続く行をキャプチャするために使用します。ただし、その.+
部分に改行を含めてはならないため、貪欲ではない必要があります。したがって、すべての量指定子はnode_patt
非貪欲でなければなりません。