Skip to content
Advertisement

How do I detect when a Dropbox folder has been updated?

I have a folder with files that are being sychronized between computers. After the files have been uploaded from computer A, I would like to copy them from computer B’s Dropbox folder to another folder. How can I detect when the Dropbox folder has been updated? I can check the Dropbox folder periodically, but maybe there is a more elegant solution?

Advertisement

Answer

Checkout inotify or incrond, you can use one of this tools to run a script once it detects changes in your folder. If you choose incrond you can run incrontab -e and add something like this:

/path/to/watched/dir IN_CLOSE_WRITE,IN_CREATE,IN_DELETE /path/to/script

In the script you can, for example, start a loop while:

[[ $(dropbox filestatus /path/to/watched/dir) != "" ]]

or:

[[ $(lsof -p $dropbox_pid | grep 'REG|DIR.*/path/to/watched/dir') != "" ]]

and then:

cp /path/to/watched/dir /path/to/copy/dir

when the loop is done.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement