0

How can I register to event that let me know when specific file is read in linux?

Can implement in c or in bash /shell script

5
  • unix.stackexchange.com/questions/12247/… Commented Apr 15, 2019 at 6:48
  • @roaima The purported dupe asks a different thing -- the title is misleading; please read the actual text of the question. This question was probably already asked a lot of times, but not there. Commented Apr 15, 2019 at 7:03
  • @mosvy the answers on the suggested dup are applicable here too. They say the same as your answer. Commented Apr 15, 2019 at 7:17
  • No, they're not applicable. They don't show how to monitor whenever a read(2) is done, as in my example. And they're cluttered with a lot of confusing stuff: loggedfs, .bash_history, etc. As I said, there probably is a dupe for this, but not that. Commented Apr 15, 2019 at 7:21
  • How about unix.stackexchange.com/questions/207304/… for a less-confusing duplicate? Commented Apr 16, 2019 at 11:59

1 Answer 1

2

Use inotify(7), inotify_add_watch(2) with IN_ACCESS, inotifywait(1), etc.

Example: In a window:

while read f; do echo "$f"; sleep 3; done </path/to/your/file
...

In another window:

inotifywait -me access /path/to/your/file
/path/to/your/file ACCESS
/path/to/your/file ACCESS
/path/to/your/file ACCESS
...
1
  • 3
    Looking in linux not Windows Commented Apr 15, 2019 at 7:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.