17
11
I just installed inotify-tools. I would like to continuously detect new file(s) with notify-tools within multiple directories recursively, and send an email using postfix. I can probably handle the send an email using postfix part. I'm just trying to figure out the best way to go about this when trying to detecting new file(s). Because sometimes multiple files are added at once.
I forgot to add several explanations regarding the commands used in the sample script thats the reason to edit my answer... I also added the script in case op wants to monitor several dirs. Regarding inotifywait tool, it is impossible to answer the question without mention it because op is using inotify-tools. By the way, I'm a newbie here so I need to learn a lot regarding netiquette, so, sorry if my answer overlaps yours, it wasn't what i want I just want to give a complete answer to op. Again, sorry. – sahsanu – 2015-08-18T13:43:08.253
No problem and welcome to SU. Learning about netiquette is usually done the hard way, as it is not really defined anywhere. – harrymc – 2015-08-18T14:14:59.317
4@sahsanu I do not agree about the whole "netiquette" thing. Each person is answering the question from there own perspective. There is no overlap between answers, nor is there an answer that has been rewritten. It is impossible for the answers to differ in that way when the question is so specific. Thank you very much for taking the time to answer the question in great detail. This has helped more than you know, for someone like me who is just learning about all of this. You have saved me countless hours. – David Custer – 2015-08-18T19:35:50.280
1
@harrymc Netiquetta is defined right here.
– David Custer – 2015-08-18T19:53:29.487Netiquette in an evolving environment cannot be absolutely defined.It's customary on this site not to duplicate answers unless they are badly written, and even then it's encouraged to correct them instead via editing. It's always your right in a democratic community not to agree. @sahsanu could have avoided my remark by referring to my previous answer while showing his script, which would have gotten your approval in any case. That's what I would have done in his place and that's my netiquette, which I believe I share with others (but not with everyone, of course). – harrymc – 2015-08-18T21:11:20.127
Would I need to call this script from crontab? – a coder – 2016-12-15T14:36:36.373
@acoder no, you should not call it using crontab, well... it depends, if you use the parameter -m it will keep running after it detects the first file created but if you don't use the -m parameter it will end once detects the first file created, I mean, if you use crontab to execute the script every x hours, days, etc, you will get duplicated processes which is not good. You should create a service to start it once your machine is booted or call it manually. – sahsanu – 2016-12-21T17:24:39.433
This only seems to work when I create a directory using linux
mkdir
. When I create it through file explorer in Windows (this is a network shared drive), it doesn't notice the folder creation at all. Is there a way around this? – frakman1 – 2019-10-31T20:56:46.517