【问题标题】:ionotifywait on shared folderionotifywait 在共享文件夹上
【发布时间】:2014-06-10 02:07:22
【问题描述】:

我在 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 文件?

【问题讨论】:

    标签: bash samba


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2022-06-30
      • 2020-03-09
      • 2021-09-22
      • 2017-12-11
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多