【发布时间】:2017-11-10 14:29:42
【问题描述】:
我想使用 inotifyway 来监控文件夹中新创建或移动的文件但只监控文件。
假设我的文件夹名为“watched_folder_test”,而我的文件名为“toto.txt”。如果我使用 mv 命令将文件移动到watched_folder_test,我会收到我想要的通知
假设在 watch_folder_test 中我有一个名为 foo 的文件夹,我创建了一个文件名“bar.txt”。我收到了我想要的通知。
但这是我的问题。如果我在 watch_folder_test 之外有一个文件夹名称 foo 我在其中有一个文件名 bar.txt ( foo/bar.txt ),我将整个文件夹移到了 watch_folder_test 中。我只收到创建 foo 的通知!与 bar.txt 无关。但是,我并不关心 foo,我只想知道“bar.txt”
这是我目前的代码
#!/bin/bash
inotifywait -mr /home/romain/depot/watched_folder_test -e create -e moved_to |
while read path action file; do
echo "The file '$file' appeared in directory '$path' via '$action'"
for ac in $action
do
isdir=`echo $ac | grep 'ISDIR'`
if [ $? == 0 ]
then
echo "It's a folder"
else
echo "It's a file"
fi
done
done
如何通知新移动文件夹中的每个文件,而不是创建文件夹本身?
【问题讨论】:
-
使用
stat过滤通知;考虑使用incron -
我在 iotifywait 之前尝试过 incron 但未能使用它。此外,当移动或创建目录时,我最终会手动获取目录中的文件。然后我切换到 inotify 的 python 版本。感谢您的反馈
标签: bash ubuntu monitoring inotify inotifywait