我正在编写脚本,一旦更改代码,该脚本将重新加载我的应用程序。
到目前为止,我拥有将提供来自更改的服务名称的部分:
inotifywait $ENVPATH --recursive --monitor --event CREATE --event MODIFY --event DELETE | grep --line-buffered -Eiv ".idea|.phpstorm.meta.php|runtime|.swp|.log"
但是当我编写代码时,我不想每秒都具有多个触发重载事件,因此我需要缓冲此流。我想读取所有可用的数据,直到每隔x秒。
如何使用bash进行操作,到目前为止,我只知道这种读取数据的方式,但这不符合我的需求
while read line
do
echo "$line"
done
答案 0 :(得分:1)
您可以在指定的时间内主动忽略inotifywait
输出的所有内容。
inotifywait ... |
while read line
do
echo "$line"
# ignore input for 1 second
timeout 1 cat >/dev/null
done
答案 1 :(得分:0)
read -t 0
将检查是否有可用输入,而没有实际阅读。您可以使用它来检查是否存在任何应忽略的缓冲事件。
inotifywait -rm -e CREATE -e MODIFY -e DELETE "$ENVPATH" \
--exclude '\.idea$|\.phpstorm.meta.php$|runtime|\.swp$|\.log$' |
# Block until there's an event.
while read -r dir event path; do
# Discard all remaining events.
while read -t 0; do read -r dir event path; done
done
请注意,您可以使用--exclude
直接从inotifywait中过滤掉文件。