【问题标题】:How to get recursive directory path using inotify-tools in terminal如何在终端中使用 inotify-tools 获取递归目录路径
【发布时间】:2013-08-17 13:39:26
【问题描述】:

我正在使用 inotify-tools,我想要一个在递归目录中创建的文件的通知

到这里我就成功了

现在我想获取在递归文件夹中创建/转储文件的目录路径

例如 abc.txt 文件被转储到 data/test 文件夹中

我希望路径是 data/test/abc.txt

下面是我在 .sh 文件中使用的代码

inotifywait -m -r --format '%f' -e modify -e move -e create -e delete /var/www/cloud/data | while read LINE; 
do 
    php /var/www/cloud/scannner/watcher.php; 
done

请帮我在递归目录中获取转储文件的路径

干杯

【问题讨论】:

    标签: php bash ubuntu-12.04 inotify inotifywait


    【解决方案1】:

    使用%w 修饰符:

    inotifywait -m -r --format '%w%f' .......
    

    要将 inotifywait 的输出作为参数传递给 php 脚本,该脚本将为 argv 变量读取它,您可以这样做:

    inotifywait -m -r --format '%w%f' ....... | while read -r line
    do 
        php script.php "$line"
    done
    

    否则,如果您希望 php 脚本从 standard input 读取 inotifywait 的输出,那么您可以通过管道传输到您的脚本:

    inotifywait -m -r --format '%w%f' ....... | php script.php
    

    【讨论】:

    • Thnx user000001...效果很好请帮助我将 $line 变量传递给 watcher.php 文件
    • @SaideepKankarla 为此添加了两个解决方案
    猜你喜欢
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2013-11-24
    • 2012-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多