I'm writing a barrier to stall the execution of a script until a certain keyword is logged. The script is pretty simple:
tail -F -n0 logfile.log | while read LINE; do
[[ "$LINE" == *'STOP'* ]] && echo ${LINE} && break;
done
or
tail -F -n0 logfile.log | grep -m1 STOP
The thing is it doesn't quit as soon as the keyword is detected, but only after the next line is written. I.e:
printf "foo
" >> logfile.log # keeps reading
printf "foo
" >> logfile.log # keeps reading
printf "STOP
" >> logfile.log # STOP printed
printf "foo
" >> logfile.log # code exits at last
Unfortunately I can't rely on the fact that another line will be logged after the "STOP" (not within an interval useful for my purposes at least).
The workaround found so far is to tail
also another file I know for sure gets updated quite frequently, but what is the "clean" solution so that the code will exit right after it logs STOP?