0

I have a dir called /media/simc/, I want to to set something up to monitor /media/simc/, and when a file is put in it (from this machine or any other on the network, it is a network mounted dir itself), I want to take that file and do stuff with it ("stuff", in this case meaning reading the contents and passing them to a command) (I also want to exclude a specific filename from the watch, say notest.txt)

The issues are I do not know what this file is going to be named, but I do know one thing it is not going to be named that I need excluded, and I have zero clue what I'm doing generally.

I thought inotifywait was the answer after some googling, and set up a quick demo for myself with this just to test that it would see stuff I put in there and do...stuff inotifywait -m /media/simc/ -e create (also tried with moved-to but not related really)

Then made a file in the dir and...nothing. After some troubleshooting I found out that I have to create a file in it through the machine itself, whereas my usecase is I have this directory available on the network and will be moving files into it from other machines, which when I do does not seem to proc the output.

So using nano test gives me what I want: /media/simc/ CREATE .test.swp but when I move a file into the directory or create one in it from another machine, no dice.

What are my options?

  • If it helps any currently what I'm doing is I manually run a bash script that prompts the user to paste in the stuff in the file then mess with it a little and load it into the command (simcraft, for anyone curious). I'm trying to automate it more so I can just save the file into this directory and have the machine automagically grab the contents, mess with them and pass them on. – user863492 Jan 26 at 23:25
  • 1
    maybe the watch command could be used in a script somehow, or it could run a script ..... watch -n 10 ls /media/simc/ will list the directory contents every 10 seconds – jsotola Jan 27 at 9:01
0

I think inotify will do what you want, but you'll have to run it on the server that exports the file. Inotify interacts with the kernel so it won't work (I believe) on a nfs client.

  • Thank you, so there's no way to get inotify to do this if I'm moving files into the folder from other machines? – user863492 Jan 28 at 5:58
  • When you update the folder on the nfs client, then inotify running on the server that exported the directory will pick it up. If your processing can only be done on the client then inotify won't help. – user103944 Jan 28 at 12:35

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.