1

I upload files for deployment into a remote directory. That remote server has a script that watches the directory for new files:

inotifywait --monitor --event create --format '%f' --quiet /foo

When a new file is detected, the deployment process starts.

The problem is the upload takes time - and the file is detected as soon as it starts writing. So the deployment fails as it attempts to use a partial file.

Is there a way to debounce the inotifywait so it reports the new file only after it is fully created?

1
  • You shouldn't be watching for create; you should be looking for close or close_write.
    – larsks
    Jun 16 at 11:44

1 Answer 1

3

As you have experienced, watching for create events isn't very useful: these events trigger when the file is created, but that doesn't tell you if any data has been written to it, nor do you know when something has finished writing data to it.

You will generally want to monitor the close or close_write events. From the man page:

EVENTS

  • close_write

    A watched file or a file within a watched directory was closed, after being opened in writeable mode. This does not necessarily imply the file was written to.

  • close_nowrite

    A watched file or a file within a watched directory was closed, after being opened in read-only mode.

  • close

    A watched file or a file within a watched directory was closed, regardless of how it was opened. Note that this is actually implemented simply by listening for both close_write and close_nowrite, hence all close events received will be output as one of these, not CLOSE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.