I would like to know when a specific file is being read and logs the process ID and executable name and also notify me by sending an email using mail.
Can kernel module do this? Is kernel module the only way to achieve this?
I would like to know when a specific file is being read and logs the process ID and executable name and also notify me by sending an email using mail.
Can kernel module do this? Is kernel module the only way to achieve this?
Reading a file invokes kernel code, so the kernel always knows. The question is how to get it to notify you.
On Linux, you can use the audit subsystem. Run auditctl to add a rule to watch this file:
auditctl -w /path/to/specific/file
The event is sent to the audit logs. You can request audit events to be emailed by configuring audispd — see How to send audit logs with audisp-remote and receive them with netcat for examples. Alternatively, set up email of audit reports; see Scott Pack's “Stump the Chump with Auditd 01”.