1

I have code like this to trigger a script in /etc/inittab:

until test -p /tmp/updates.pipe
do
    sleep 0.25
done

Which I want to refactor since the sleep floods debug logs, when debugging with set -x.

IIUC inotifywait only watches on directories.

inotifywait -e create /tmp

So how do I make it only proceed after seeing the CREATE event of the /tmp/updates.pipe file, and not any other file in /tmp?

4

2 回答 2

1

grep 的安静标志会导致它在看到匹配项时立即爆发。以下应该在 bash 下工作。

grep -q updates.pipe <(inotifywait -e create -m /tmp)

于 2012-08-07T01:34:36.260 回答
0

像这样的东西怎么样:

while read OUTPUT
do
    if echo $OUTPUT | grep -q "CREATE updates.pipe"; then break; fi
done < <(inotifywait -qm -e create /tmp)

不过,这不适用于所有 shell。

这是另一个适用于所有外壳的解决方案:

inotifywait -qm -e create /tmp | while read OUTPUT
do
    if echo $OUTPUT | grep -q "CREATE updates.pipe"; then break; fi
done

但是由于一些神秘的原因,它只在下一个输出之后才中断CREATE updates.pipe,有人知道为什么吗?

于 2012-08-06T12:17:21.073 回答