Bash 如何等待消息出现在登录shell中
能否提供简洁的解决方案,在给定文件中出现文本片段之前阻止脚本的执行?使用Bash 如何等待消息出现在登录shell中,bash,shell,Bash,Shell,能否提供简洁的解决方案,在给定文件中出现文本片段之前阻止脚本的执行?使用inotifywait inotifywait有效地等待对文件的更改 例如:- 终止要阻止的进程 inotifywait-q-e modify/path/to/file/containing/snippet 检查文件中的更改 如果更改匹配,则重新启动脚本 永远等待 grep -q 'ProducerService started' <(tail -f logs/batch.log) grep-q“ProducerSe
inotifywait
inotifywait有效地等待对文件的更改 例如:-
inotifywait-q-e modify/path/to/file/containing/snippet
grep -q 'ProducerService started' <(tail -f logs/batch.log)
grep-q“ProducerService start”在很大程度上取决于缓冲和您使用的操作系统。Linux提供了几种基于inotify
(man7inotify
)的非标准接口,但是bash
中没有这样做的功能。即使是inotify
也只会在刷新缓冲区后检测到更改。如果编写程序使用大的缓冲区,那么在程序关闭之前(通常刷新缓冲区),文件大小可能不会有可检测的变化。请注意,使用-KILL
信号(KILL-9
)终止进程可能会导致缓冲区未刷新和数据丢失。
timeout 30s grep -q 'ProducerService started' <(tail -f logs/batch.log)
timeout 30s grep -q 'ProducerService started' <(tail -f logs/batch.log) || exit 1