php - Notify of new files with inotify -


i need make script notifies log file when new file enters directory. use inotify shell script or php, examples have found in c. can give me example of this?

in addition, can inotify know when file done being copied?

this shell command write logfile whenever file created in /path/to/dir:

inotifywait -m -e create /path/to/dir >>logfile 

explanation:

  • -m tells inotifywait keep running. default exit after first event

  • -e create tells inotifywait report on file create events.

  • /path/to/dir target directory watch. subdirectories not monitored unless recursive option, -r specified.

  • >>logfile tells shell redirect output file logfile. if leave part off, output directed stdout , can watch in real time files created.

monitoring more events

inotifywait report on several different events. example, ran inotifywait in 1 window while writing file window:

$ inotifywait -m . setting watches. watches established. ./ open myfile ./ modify myfile ./ modify myfile ./ modify myfile ./ close_write,close myfile 

because above has no redirection, output appears on terminal.

the open event signifies files initial creation. close events indicates process done.

the exact set of events inotifywait show depends on system calls program monitoring uses. test above find out.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -