Dynamically add paths to inotify

I have initiated an inotify process with --fromfile option and the file contain the paths to be monitored.

/usr/local/maldetect/inotify/inotifywait -d -r -o /usr/local/maldetect/inotify/inotify_log --fromfile /usr/local/maldetect/sess/inotify.paths.28364 --exclude (^/var/tmp/mysql.sock) --timefmt %d %b %H:%M:%S --format %w%f %e %T -m -e create,move,modify

The file /usr/local/maldetect/sess/inotify.paths.28364 contain entries such as below.

/home/user1/public_html
/home/user2/public_html
/home/user3/public_html

There are almost 800 entries like this. What I need is, when a new user is created, the path /home/user4/public_html, should add the path dynamically to the existing inotify process without needing to re-initate the inotify process. As the initialization of inotify process is a bit resource hogging. Or anyway by which, if we add the path /home/user4/public_html to the file /usr/local/maldetect/sess/inotify.paths.28364, the inotify process will dynamically read it.

Have you looked at the inotify_add_watch(2) man page?

1 Like

Thanks Don,

I am checking that only now.

---------- Post updated at 07:40 AM ---------- Previous update was at 07:28 AM ----------

It describes the usage of inotify_add_watch with a c program. I need to use with the compiled binary /usr/local/maldetect/inotify/inotifywait.