You are not logged in.

#1 2011-08-24 14:52:54

zebulon
Member
Registered: 2008-10-20
Posts: 358

Need to monitor any file change in the system, in real time

Hi,

I am running a program that I suspect may be doing changes in the filesystem, but I do not know which ones. I would like to know if there is a daemon/program that could help me monitor those changes. I tried AIDE, however, it works by creating a database of checksums for each file and does not report in real time potential changes. I would rather use a program that logs changes and timestamp them. Furthermore, AIDE is not useable with /var files, since there are many of them and they change so often. Is there another good solution?

Alternatively I would like to run the program with monitoring. For instance, run the process as:

monitor_program my_program_to_monitor logfile

This would dump in logfile what my_program_to_monitor does to the filesystem.

Thanks in advance.

Last edited by zebulon (2011-08-24 15:44:10)

Offline

#2 2011-08-24 16:16:33

mang
Member
From: stockholm/sweden
Registered: 2008-11-11
Posts: 27
Website

Re: Need to monitor any file change in the system, in real time

inotify! it's the kernels built in API for monitoring file system events, its real time and very easy
install inotify-tools with pacman, you can then use it like

inotifywait -m -e MODIFY -r /path/to/your/directory/to/monitor

to recursively monitor changes to files to that directory

Offline

#3 2011-08-24 16:49:55

zebulon
Member
Registered: 2008-10-20
Posts: 358

Re: Need to monitor any file change in the system, in real time

Many thanks! That's look good. I looked at the man, but could not find: is it possible to output the PID of the process doing the MODIFY ?

Offline

#4 2011-08-24 18:19:29

mang
Member
From: stockholm/sweden
Registered: 2008-11-11
Posts: 27
Website

Re: Need to monitor any file change in the system, in real time

no, at least with inotifywait, it is not possible. once you know what file is being changed you can use "lsof" to see what process have opened that file.
i tried the following to search lsof output first thing when inotifywait finds a file change.

file=$(inotifywait -r /home/mang/watch --format %w | sed 's/.$//'); lsof | grep $file

while in another terminal running "vi /home/mang/watch/test"
the output is:

zsh       12574       mang  cwd    DIR     254,11     4096 4723089 /home/mang/watch
vi        16790       mang  cwd    DIR     254,11     4096 4723089 /home/mang/watch

try it!

Offline

#5 2011-08-25 07:38:33

zebulon
Member
Registered: 2008-10-20
Posts: 358

Re: Need to monitor any file change in the system, in real time

That works very well. Many thanks for your help.

Offline

Board footer

Powered by FluxBB