Bash Timeout Loops

From NovaOrdis Knowledge Base
Revision as of 19:50, 5 May 2021 by Ovidiu (talk | contribs) (Ovidiu moved page Bash Timeout Loop to Bash Timeout Loops without leaving a redirect)
Jump to navigation Jump to search

Internal

Overview

...
local timeout_sec=...
local t0=$(date '+%s')
local remaining=$(expr ${timeout_sec} + ${t0} - $(date '+%s'))
while [[ ${remaining} -gt 0 ]]; do
    debug "remaining ${remaining} secs ..."
    sleep 1
    remaining=$(expr ${timeout_sec} + ${t0} - $(date '+%s'))
done