4

I have inotifywait(version 3.14) on Linux to monitor a folder that is shared with Samba Version 4.3.9-Ubuntu.

It works if I copy a file from Linux machine to samba share(that is on different machine, under Linux as well).

But if I copy a file from Windows machine inotify won't detect anything. Spaces or no spaces, recursive or not result is the same.

printDir="/media/smb_share/temp/monitor"
inotifywait -m -r -e modify -e create "$printDir" |  while read line
do
    echo "$line"
done

Does anyone have any ideas of how to solve it?

bstand
  • 51
  • 1
  • 6
  • If you remove the `while` loop do you get any timely output from `inotifywait`? – roaima Jun 06 '16 at 09:37
  • 1
    It should work. I have something like that running and i don't see any obvious mistakes in your setup. Please double check for "stupid" mistakes like using the wrong directory or server ;) – Silent-Bob Jun 06 '16 at 09:41
  • Without the loop it still doesn't catch anything. Yes, i tripled check the directory if i copy from Linux it catches an event but not from Windows. – bstand Jun 06 '16 at 10:11
  • If you remove the `-e modify -e create` filters what events do you get? – roaima Jun 06 '16 at 10:24
  • Nothing, no events if copy from Windows. Copying from Linux i get all kinds of different events including the ones i am looking for. – bstand Jun 06 '16 at 10:26
  • Your directory is `/media/smb_share/...` this _is_ a local filesystem? And it matches exactly the path you've defined for the share in your local `smb.conf`? `inotifywait` can only see events on local filesystems. – roaima Jun 06 '16 at 11:02
  • Yes it is. Script runs on a server that shares this directory through Samba to Linux and Windows clients. Only Linux clients were happy about it though. – bstand Jun 06 '16 at 11:04
  • Very strange. Works for me from Windows to a Samba share on my server's local filesystem. – roaima Jun 06 '16 at 13:43
  • Incidentally, if that workaround script is your own (reluctant) answer, please move it out of the question and into an answer. You can then accept that answer (if you get nothing better). – roaima Jun 06 '16 at 13:44

2 Answers2

1

Ok, its an ugly workaround but for my case it should work in ~90% of cases.

temPrint=/dev/shm/print
fcheck_1=$temPrint/fcheck_1
fcheck_new=$temPrint/fcheck_new
fcheck_old=$temPrint/fcheck_old
fcheck_preprint=$temPrint/fcheck_preprint
fcheck_print=$temPrint/fcheck_print
printDir="/media/smb_share/temp/monitor"

test -d $temPrint || mkdir $temPrint

while [ true ]; do
  test -e $fcheck_new && rm $fcheck_new
  test -e $fcheck_old || touch $fcheck_old
  test -e $fcheck_print && rm $fcheck_print

  ls -l "$printDir"/*.pdf > $fcheck_1
  while read line
  do
    echo "${line#*"/"}" | sed "s#^#/#" >> $fcheck_new
  done < $fcheck_1

  rt=$(diff $fcheck_new $fcheck_old | grep "<")
  if [ "$rt" ]; then
    echo "$rt" > $fcheck_preprint
    while read line
    do
      echo "${line#*"/"}" | sed "s#^#/#" >> $fcheck_print
    done < $fcheck_preprint

    while read line
    do
      echo "$line"
    done < $fcheck_print

    cp $fcheck_new $fcheck_old
  fi
  sleep 20
done
bstand
  • 51
  • 1
  • 6
0

You should give fileschanged a chance

I just tested it with mounted CIFS drives from Windows. It worked like a charme with almost no latency or server load.

  • To install:
    sudo apt-get install fileschanged
    
  • To monitor e.g. your home folder for any new or changed files
    fileschanged -s created,changed -t1 $PWD
    
  • The output will look like this:
    /mnt/winshare/DevRep/VMTest/trigger_test1 folder/test3
    /mnt/winshare/DevRep/VMTest/trigger_test1 folder/test3
    /mnt/winshare/DevRep/VMTest/trigger_test1 folder/test4
    

As you can see, it works with spaces inside paths as well.

AdminBee
  • 21,637
  • 21
  • 47
  • 71