您能否提供简洁的解决方案来阻止脚本执行,直到文本片段出现在给定文件中?
永远等待
grep -q 'ProducerService started' <(tail -f logs/batch.log)
超时等待
timeout 30s grep -q 'ProducerService started' <(tail -f logs/batch.log)
等待超时,通知错误
timeout 30s grep -q 'ProducerService started' <(tail -f logs/batch.log) || exit 1
等待下一个插入的实例(由@Dan-Dev)
timeout 30s grep -q 'ProducerService started' <(tail -n0 -f logs/batch.log)
使用
inotifywait
示例:-
inotifywait -q -e modify /path/to/file/containing/snippet