如何等待消息出现在登录shell

nom7f22z  于 2023-08-07  发布在  Shell
关注(0)|答案(2)|浏览(95)

你能提供整洁的解决方案来阻止脚本的执行,直到文本片段出现在给定的文件中吗?

pgky5nke

pgky5nke1#

永远等待

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

0yg35tkg

0yg35tkg2#

使用inotifywait
inotifywait有效地等待文件的更改
例如:-
1.终止要阻止的进程

  1. inotifywait -q -e modify /path/to/file/containing/snippet
    1.检查文件中的更改
    1.如果更改匹配,则重新启动脚本

相关问题