Обнаружение изменений папки

существуйте какой-либо способ обнаружить, если файл помещается в папку (Изменение содержания каталога) (не подкаталог), и Выполните сценарий PHP (Никакой Cron/Crontab) через CLI в человечности 18.04?

0
задан 31 October 2019 в 00:32

2 ответа

Использовать inotify который должен быть частью inotify-tools пакет.

Сценарий, работающий в фоновом режиме, мог быть похожим на это

#!/bin/sh

while : 
do
  inotifywatch -e moved_to -e create /watched/dir && {
    php -f /path/to/script.php
  }
done
1
ответ дан 22 December 2019 в 00:09

Как указано в предыдущем ответе, установке inotify-tools:

sudo apt install -y inotify-tools

Теперь можно использовать команду inotifywait:

inotifywait -m /your/dir -e create -e move |
while read path action file; do
  # your preferred command here
done

С inotifywait --help Вы получаете события, за развитием которых можно следить:

Events:
    access      file or directory contents were read
    modify      file or directory contents were written
    attrib      file or directory attributes changed
    close_write file or directory closed, after being opened in
                writable mode
    close_nowrite   file or directory closed, after being opened in
                read-only mode
    close       file or directory closed, regardless of read/write mode
    open        file or directory opened
    moved_to    file or directory moved to watched directory
    moved_from  file or directory moved from watched directory
    move        file or directory moved to or from watched directory
    create      file or directory created within watched directory
    delete      file or directory deleted within watched directory
    delete_self file or directory was deleted
    unmount     file system containing file or directory unmounted
2
ответ дан 22 December 2019 в 00:09

Другие вопросы по тегам:

Похожие вопросы: