wait_init.ttl V2.0.0 now polls
bcmcmd -n 0 -c ps | grep -w up | wc -l
bcmcmd -n 1 -c ps | grep -w up | wc -l
and proceeds only when BOTH exceed 216, so the baseline is taken with
the data plane actually up rather than merely with pmon answering.
V1.0.0 could use `wait "Thermal Not detected" prompt` because that was a
string-presence test. Comparing a count needs the value captured, so the
count is wrapped in an echo marker and read with waitregex +
groupmatchstr1 + str2int. The command echo cannot false-match: it reads
"PORTS0=$(bcmcmd ..." and the pattern requires a digit immediately after
the "=". The optional-space allowance covers a wc that pads its output.
The two thresholds are compared in nested ifs rather than with `and`,
which is bitwise in TTL.
WT_MIN and WT_INTERVAL are at the top of the file. The enter/exit prompt
contract is unchanged, so Script A's surrounding waits still line up.
Script A -> V1.0.4.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014RetWKFZFG1ZHcitQAyhwM
69 lines
2.6 KiB
Turtle
69 lines
2.6 KiB
Turtle
; =============================================================================
|
|
; File : utils/wait_init.ttl
|
|
; Version : V2.0.0
|
|
; Date : 2026-08-21
|
|
; Author : ETWen
|
|
; =============================================================================
|
|
; Wait until BOTH switch units report more than WT_MIN ports up:
|
|
; bcmcmd -n 0 -c ps | grep -w up | wc -l
|
|
; bcmcmd -n 1 -c ps | grep -w up | wc -l
|
|
;
|
|
; Enter : prompt of the previous command is NOT consumed.
|
|
; Exit : a command has been sent, prompt NOT consumed (caller does the wait).
|
|
;
|
|
; Why the "PORTS0=" marker instead of reading the number straight off the
|
|
; screen: TTL can only test for a string, so counting requires capturing the
|
|
; output. Wrapping the count in an echo gives waitregex a unique anchor, and
|
|
; the ECHO of the command itself cannot false-match -- it reads
|
|
; "PORTS0=$(bcmcmd ..." and the regex demands a digit right after the "=".
|
|
;
|
|
; Version History:
|
|
; V1.0.0 2026-08-21 Initial Version (waited on "show platform temperature"
|
|
; until it stopped reporting "Thermal Not detected")
|
|
; V2.0.0 2026-08-21 Wait on the bcmcmd port-up count of BOTH switch units
|
|
; instead of the thermal sensors; proceed only when both
|
|
; are greater than WT_MIN (216).
|
|
; =============================================================================
|
|
WT_MIN = 216 ; both units must report MORE than this many ports up
|
|
WT_INTERVAL = 10 ; seconds between polls
|
|
|
|
timeout = 60 ; per-wait cap; bcmcmd ps is not instant
|
|
wait prompt_sonic_root
|
|
|
|
:WAIT_PORTS
|
|
; --- unit 0 -----------------------------------------------------------------
|
|
wt_up0 = 0
|
|
sendln "echo PORTS0=$(bcmcmd -n 0 -c ps | grep -w up | wc -l)"
|
|
waitregex "PORTS0=[ ]*([0-9]+)"
|
|
if result = 1 then
|
|
str2int wt_up0 groupmatchstr1
|
|
endif
|
|
wait prompt_sonic_root
|
|
|
|
; --- unit 1 -----------------------------------------------------------------
|
|
wt_up1 = 0
|
|
sendln "echo PORTS1=$(bcmcmd -n 1 -c ps | grep -w up | wc -l)"
|
|
waitregex "PORTS1=[ ]*([0-9]+)"
|
|
if result = 1 then
|
|
str2int wt_up1 groupmatchstr1
|
|
endif
|
|
wait prompt_sonic_root
|
|
|
|
; --- both above the threshold? ----------------------------------------------
|
|
; Nested ifs rather than "and": in TTL "and" is bitwise, so keeping the two
|
|
; comparisons separate leaves no room for precedence surprises.
|
|
if wt_up0 > WT_MIN then
|
|
if wt_up1 > WT_MIN then
|
|
goto PORTS_OK
|
|
endif
|
|
endif
|
|
|
|
pause WT_INTERVAL
|
|
goto WAIT_PORTS
|
|
|
|
:PORTS_OK
|
|
timeout = 0
|
|
; Exit contract: send something without waiting, so the caller's next
|
|
; "wait prompt_sonic_root" has a prompt to match.
|
|
sendln ""
|