I am trying to use inotifywait to monitor a folder:
inotifywait -m -r /home/oshiro/Desktop/work_folder
The command works and if I create files in that folder, all seems to work correctly.
While the folder is being monitored, if I delete it, I get the following output:
/home/oshiro/Desktop/work_folder/ MOVE_SELF
/home/oshiro/Desktop/work_folder/ OPEN,ISDIR
/home/oshiro/Desktop/work_folder/ CLOSE_NOWRITE,CLOSE,ISDIR
/home/oshiro/Desktop/work_folder/ MOVE_SELF
/home/oshiro/Desktop/work_folder/ ATTRIB,ISDIR
/home/oshiro/Desktop/work_folder/ OPEN,ISDIR
/home/oshiro/Desktop/work_folder/ DELETE Untitled Document
/home/oshiro/Desktop/work_folder/ DELETE Untitled Document 2
/home/oshiro/Desktop/work_folder/ CLOSE_NOWRITE,CLOSE,ISDIR
/home/oshiro/Desktop/work_folder/ DELETE_SELF
If I then re-create that folder again, while the monitoring is still taking place, inotifywait doesn't seem to continue monitoring it, unless I run inotifywait -m -r /home/oshiro/Desktop/work_folder
again.
How do I get around this issue? I basically want to monitor a USB stick which will be plugged in and removed many times during a day. When it's unplugged and plugged back in, I think inotifywait will stop monitoring it, the same way the folder above was deleted and re-created where inotifywait wasn't able to continue monitoring it, unless I run the above command again, i.e. inotifywait -m -r /home/oshiro/Desktop/work_folder
Should I be using something more appropriate for such tasks and not use inotifywait? cron is not suitable for my needs, as I am not after time based actions, I am after event based actions.