【发布时间】:2016-05-02 06:55:55
【问题描述】:
我有一个 shell 脚本,我在其中使用“inotifywait”来监控三个目录。一旦文件进入目录“dirToProcess”,就会完成一些处理,然后将文件移动到“successDir”或“failedDir”目录。
现在,只要任何文件被移动或复制到我希望 inotifywait 执行的任何目录中。
这是我正在执行的代码:
inotifywait $dirToProcess $successDir $failedDir -e create -e moved_to --
exclude "\.(swx|swp|end|en1)" |
while read path action file; do
if [ -f $dirToProcess/$file ]; then
doSomething;
elif [ -f $successDir/$file ]; then
cleanDir $successDir # function which has some specific logic
exit 0;
elif [ -f $failedDir/$file ]; then
cleanDir $failedDir # function which has some specific logic
exit 0;
else
c4lx_log "File $file not in poll, archive or failed, then why did we get notified?"
exit 0;
fi
问题来了: 一旦文件进入“dirToProcess”,inotifywait 就会注意到它并被调用。但是在处理文件被移动到'$successDir'或'$failedDir'时(通过在'dirToProcess'中处理文件的相同代码inotifywait不会被执行。但是如果我在这两个目录中的任何一个中手动移动文件,一切似乎工作正常。
有人可以在这里给我一些指示或解释我是否在这里遗漏了任何细节。
(我尝试在 inotifywait 中使用 -m 或 -r 选项,但似乎不起作用)
谢谢
【问题讨论】: