共享文件夹上的inotifywait

时间:2014-06-09 17:29:43

标签: bash samba

我在Ubuntu 10.04服务器上设置了一个bash脚本,只要在此服务器的./incoming/目录中创建PDF,就会生成一个新的PDF,新的PDF在./outgoing/文件夹中创建。这两个文件夹都在本地计算机上,并与samba版本3.4.7共享。该脚本使用inotifywait来监视传入目录(根据Script to monitor folder for new files)。

inotifywait -m ./incoming/ -e create -e moved_to |
    while read path action file; do
        echo "The file '$file' appeared in directory '$path' via '$action'"
        # Generate PDF using $file into ./outgoing/
    done

当我使用bash或Windows资源管理器复制文件时,这很正常,但是当我在Windows 7客户端上从MS Outlook(或Word)保存test.pdf附件时,我会进行多次激活;

The file './in/test.pdf' appeared in directory './incoming/' via 'CREATE'
The file './in/B90C4C41.tmp' appeared in directory './incoming/' via 'CREATE'
The file './in/BE5AC54E.tmp' appeared in directory './incoming/' via 'MOVED_TO'
The file './in/test.pdf' appeared in directory './incoming/' via 'MOVED_TO'

为什么这样做?我该怎样预防呢?或者我应该使用sleep解决它并忽略.tmp个文件?

1 个答案:

答案 0 :(得分:0)

只需忽略非PDF文件,因为您可能无法对目录中创建的临时文件执行任何操作。

while read path action file; do
    [[ $file = *.pdf ]] || continue
    echo "..."
done