Modified files on the cloud by inotifywait

Discussion in 'Command Line' started by Sandro kensan, May 18, 2014.

  1. Sandro kensan

    Sandro kensan New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Hi,
    i would like to copy on the cloud some selected files when modified. The script is this:
    Code:
    while : do
      file = $(inotifywait --fromfile /tmp/list.txt --event modify --format "%w")
      cp -f "$file" $HOME/cloud
    done
    The problem is that inotifywait don't print the files that has been modified. It is a bug? It is my mistake?

    Other example:
    Code:
    $ inotifywait file1.txt file2.txt --event modify --format %w
    print only
    Code:
    Setting up watches.
    Watches established.
    and exits when event occurs.

  2. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,226
    Likes Received:
    414
    Trophy Points:
    83
    inotifywait waits for changes to files, it does not show files that have been
    changed.



    http://linux.die.net/man/1/inotifywait

    an example:A short shell script to efficiently wait for httpd-related log messages and do something appropriate.
    Code:
    #!/bin/sh
    while inotifywait -e modify /var/log/messages; do
      if tail -n1 /var/log/messages | grep httpd; then
        kdialog --msgbox "Apache needs love!"
      fi
    done
    
  3. Sandro kensan

    Sandro kensan New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Tanks ryanvade for the answer. So I think my only option is to modify the source code of inotifywait or to use other inotify in other language like PHP or Phyton: do you agree?
  4. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,226
    Likes Received:
    414
    Trophy Points:
    83
  5. Sandro kensan

    Sandro kensan New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    I would like a real time check.
  6. Sandro kensan

    Sandro kensan New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    I have found the solution:
    Code:
    while true; do file=$( inotifywait -q --fromfile /tmp/lista.txt --format
    '%w' --event DELETE_SELF,MODIFY ); cp -f "$file" "Cloud"/; done
    See this post:

    stackoverflow com/questions/2754954/inotify-delete-self-when-modifying-and-saving-a-file

    Kwrite and other editors don't modify the files thy deleted the files (moove, mv). nano modify the files. Also inotifywait died when the files that is monitor is deleted so no output is send.

Share This Page