inotifywait -m在长期运行过程后不会处理超过1个文件

发布于 2025-01-25 16:09:30 字数 805 浏览 3 评论 0 原文

我有一个脚本,可以检测Close_write上的文件,并在它们上运行一个约5分钟的过程。这些文件以高达100的批量写入目录。问题在于,InotifyWait仅检测批处理中的第一个文件,并且除非手工从目录中删除并放回后面,否则不会处理后续文件。这是我的脚本:

#!/bin/bash

inotifywait -r -e close_write -e moved_to --format "%f" $TARGET -m | while read file
    do
        if [[ "$file" =~ .*mp4$ ]]; then
            echo "Detected $file"
            /usr/bin/python3 LongRunningProgram.py -i $TARGET/$file -o $PROCESSED -u $UPLOADPATH -c $C
        fi
    done

它是由SystemCtl服务所做的:

[Unit]
Description=Description
After=network.target

[Service]
Type=idle
user=pi
WorkingDirectory=/home/pi
ExecStart=/bin/bash /home/pi/notify.sh OutPath C
Restart=on-failure

[Install]
WantedBy=multi-user.target

我很困惑为什么它似乎只能识别第一个文件,而在这样的运行时则不得识别后续文件,但是,如果我用Sleep 300替换长期运行的程序似乎效果很好。

I have a script that detects files on close_write and runs an ~5 minute process on them. These files are written to the directory in batches of up to 100. The issue is that inotifywait only detects the first file in the batch and does not process the subsequent files unless they are removed from the directory by hand and put back. Here is my script:

#!/bin/bash

inotifywait -r -e close_write -e moved_to --format "%f" $TARGET -m | while read file
    do
        if [[ "$file" =~ .*mp4$ ]]; then
            echo "Detected $file"
            /usr/bin/python3 LongRunningProgram.py -i $TARGET/$file -o $PROCESSED -u $UPLOADPATH -c $C
        fi
    done

it is maintained by a systemctl service written like so:

[Unit]
Description=Description
After=network.target

[Service]
Type=idle
user=pi
WorkingDirectory=/home/pi
ExecStart=/bin/bash /home/pi/notify.sh OutPath C
Restart=on-failure

[Install]
WantedBy=multi-user.target

I am confused as to why it only seems to recognize the first file but not subsequent files when run like this, however if I replace the long running program with sleep 300 it seems to work fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蔚蓝源自深海 2025-02-01 16:09:30

我忽略解释“长期运行过程”的错。 InotifyWait 旋转的python脚本被称为FFMPEG进程,以在写入目录的MP4文件上进行工作。在循环中使用中的FFMPEG有一个错误。我关注此答案使用 > -nostdin 标志,并且似乎已经解决了问题。希望这个答案可以帮助其他人解决这个问题:)

My fault for neglecting to explain what the "long running process" was doing. The python script that is called as a result of inotifywait spins up an ffmpeg process to do work on the MP4 files that were written to the directory. There is a bug with ffmpeg when using it in a while loop. I followed This answers solution to use the -nostdin flag and that appears to have solved the issue. Hopefully this answer helps someone else with this problem :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文