0

I need to watch a file system for the creation of new files of a specific type. Thinking that this would be a perfect use case for inotifywatch, I set out to try and make something work. I went to the man pages for the program, tried to implement things, got errors.. then tried to run their basic example.

inotifywatch -v -e access -e modify -t 60 -r ~/

I got the same eorror which was

Establishing watches...
OK, /home/mcamp is now being watched.
Total of 27243 watches.
Finished establishing watches, now collecting statistics.
Will listen for events for 30 seconds.
total access modify filename
Segmentation fault (core dumped)

What's causing this? inotifywait works for a single file.. I haven't had any luck with google. Has anyone else seen this error before and know how to handle it?

TIA

Matt Camp
  • 101
  • 1
    Perhaps it has something to do with the even queue overflowing, as stated in the man page. There may be far too many files changing! It would help if you told us how quickly the segfault happens. – Bib Sep 15 '21 at 18:18
  • 1
    You can still use inotifywait in monitor mode using the -m option (and a loop, in shell or any other language). eg: https://unix.stackexchange.com/questions/24952/script-to-monitor-folder-for-new-files . caveat: special characters in filenames might not be easy to handle – A.B Sep 15 '21 at 20:42
  • thanks yea I just figured that out... and got it all working now. – Matt Camp Sep 16 '21 at 13:08

1 Answers1

0

as mentioned in the comments I was able to get things working an alternative way using inotifywait. An example of what I did is below:

#!/bin/sh

function execute() { echo "Do Stuff like ping an Airflow API: $@" }

inotifywait -r --include ".wav|.mp3"
--monitor
--event create
--event move
--event delete
--format %e,%w%f
~/
| while read; do execute "${REPLY% }" done

Matt Camp
  • 101