#!/bin/bash
# @param $1: string/pattern to match
# @param $2: file to read
# @param $3: max timeout (defaults to 5s)
function in_file_contents {
local maxTimeout="${3:-2s}";
if [[ "$#" -lt 2 ]]; then
fatal_error "Missing parameters" 1
fi
timeout --signal SIGKILL --foreground "$maxTimeout" grep -iq "$1" <(tail -f "$2")
}
outFile=$(mktemp)
# pretend we have a long running task writing to a logfile
yes 'yes' | head -n 1000 > $outFile &
echo "testing positive match"
in_file_contents "yes" $outFile || echo "This should not print"
echo "passed"
echo "testing negative match"
in_file_contents "no" $outFile || echo "Exited with: $!"
To embed this project on your website, copy the following code and paste it into your website's HTML: