我写了一个bash脚本来监控特定目录“/root/secondfolder/”脚本如下:
#!/bin/sh
while inotifywait -mr -e close_write "/root/secondfolder/"
do
echo "close_write"
done
当我在“/root/secondfolder/”中创建一个名为“fourth.txt”的文件并向其中写入内容、保存并关闭它时,它会输出以下内容但不会回显“close_write”:
/root/secondfolder/ CLOSE_WRITE,CLOSE fourth.txt
有人能指出我正确的方向吗?
最佳答案
您离解决方案不远了。如果您想在 while
语句中使用 inotifywait
,则不应使用 -m
选项。使用此选项 inotifywait
永远不会结束,因为它是 monitor
选项。所以你永远不会进入 while
。
这应该有效:
#!/bin/sh
while inotifywait -r -e close_write "/root/secondfolder/"
do
echo "close_write"
done
关于linux - 在脚本中使用 inotify 监控目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24567608/