Reputation: 20966
Could you please provide neat solution to block execution of the script until text snippet appear in the given file?
Upvotes: 2
Views: 4774
Reputation: 20966
Wait forever
grep -q 'ProducerService started' <(tail -f logs/batch.log)
Wait with timeout
timeout 30s grep -q 'ProducerService started' <(tail -f logs/batch.log)
Wait with timeout, notify error
timeout 30s grep -q 'ProducerService started' <(tail -f logs/batch.log) || exit 1
Wait for next inserted instance (by @Dan-Dev)
timeout 30s grep -q 'ProducerService started' <(tail -n0 -f logs/batch.log)
Upvotes: 14
Reputation: 2286
Use inotifywait
inotifywait efficiently waits for changes to files
example:-
inotifywait -q -e modify /path/to/file/containing/snippet
Upvotes: 1