zeek/testing/scripts/wait-for-file
Arne Welzel c826118385 Merge remote-tracking branch 'origin/topic/etyp/centos-missing-file-test-fail'
* origin/topic/etyp/centos-missing-file-test-fail:
  Fix flaky `missing-file-initially` test
2024-10-04 19:32:48 +02:00

27 lines
602 B
Bash
Executable file

#! /usr/bin/env bash
# Sleeps until a file comes into existence.
if [[ $# -ne 2 ]]; then
echo >&2 "usage: $0 <file to wait for> <max secs to wait>"
exit 1
fi
SLEEP_INTERVAL=0.1
SLEEP_INTERVAL_MS=100
wait_file=$1
max_wait=$2
# Avoid floating point arithmetic by using milliseconds
wait_countdown=$((${max_wait}000 / SLEEP_INTERVAL_MS))
while [[ ! -e $wait_file ]]; do
wait_countdown=$((wait_countdown - 1))
if [[ $wait_countdown -le 0 ]]; then
echo >&2 "error: file '$wait_file' does not exist after $max_wait seconds"
exit 1
fi
sleep $SLEEP_INTERVAL
done