Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if the directory content has changed with shell script or python

I have a program that create files in a specific directory. When those files are ready, I run Latex to produce a .pdf file. So, my question is, how can I use this directory change as a trigger to call Latex, using a shell script or a python script?

Best Regards

like image 741
Frias Avatar asked Feb 01 '11 12:02

Frias


People also ask

How do I see directory changes in Python?

Autoreload is a simple python script to watch a directory for changed files and restarts a process when the change is detected. For instance, I run ./autoreload python main.py. This first runs python main.py, then watches the current working directory and all subdirectories for changes.

How can you tell if a file has been changed?

You can use the stat command on a file to check access and modification times or set up RCS to track changes. You can use MD5 or sum to get the current state of the file, copy that value to a file and then that file to verify that the original file wasn't changed.

How do I know if a python file is modified?

Python's os. path. getmtime() method can be used to determine when the given path was last modified.


1 Answers

inotify replaces dnotify.

Why?

...dnotify requires opening one file descriptor for each directory that you intend to watch for changes...

Additionally, the file descriptor pins the directory, disallowing the backing device to be unmounted, which causes problems in scenarios involving removable media. When using inotify, if you are watching a file on a file system that is unmounted, the watch is automatically removed and you receive an unmount event.

...and more.

More Why?

Unlike its ancestor dnotify, inotify doesn't complicate your work by various limitations. For example, if you watch files on a removable media these file aren't locked. In comparison with it, dnotify requires the files themselves to be open and thus really "locks" them (hampers unmounting the media).

Reference

like image 53
Dennis Williamson Avatar answered Sep 19 '22 22:09

Dennis Williamson