Link to home
Start Free TrialLog in
Avatar of Ziggie013
Ziggie013

asked on

Monitor file system for new files.

I was looking into inotify (built into the 2.6.15 kernel) as a way to monitor a file system for changes, then do something once those changes occur.

I'm currently running RHEL AS3 (based on the 2.4 kernel) and have had...little success moving over to the 2.6 kernel (long story).

Does anyone know of any event driven utilities that can act when a file system has had a new file added to it?  

for example, user jim saves a file into /home/jim/watchme  I want this monitoring tool to notice the new file and copy it to a log directory as well (cp /home/jim/watchme/newfile /var/log/jim)

Bad example, but I hope it gets the jist of what I want to do accross.  If inotify is the only way to do this, then I'm back to the drawing board.
Avatar of guruyaya
guruyaya

You can add a cron job, going somthing like this:

find / -mtime 1 -exec cp -p {} /log/{} \;

This will show you the newly modified files in the system. not by thier creation time. Hopfully, this serves you good enoth.
use tripwire

http://www.tripwire.com/products/enterprise/ost/

its open source software.



Avatar of Ziggie013

ASKER

guruyaya - is there a way to drop the path when it copies the file?  or do I have to create a directory for every directory that it's going to copy?  Neat script otherwise!

arvind - I'm not sure tripwire will do what I want.  It certainly tells me what files has been changed, but doesn't act upon that information, that I can see...
SOLUTION
Avatar of guruyaya
guruyaya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's good, except doing this every minute could kill my server.

Do you know of any event driven methods of doing this?

If you do not mind to write some lines of C-code, you could use the "file alteration daemon" (famd).
Just write a little code snippet, which connects to famd, registers a given directory for monitoring and waits for an event, then takes any action you want and unregisters the monitor. See fam(3) for details.

HTH,

-XoF-
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To second the last response see this article
http://www.devchannel.org/devtoolschannel/04/05/13/2146252.shtml
and you might think about using a scripting language instead of C (it will be faster but maybe not as flexible as you might want).
Take a look @ this:
http://www.pablotron.org/software/fam-ruby/examples/dirmon.rb
http://www.macosxhints.com/article.php?story=20031001073403810
http://ayesha.phys.virginia.edu/~bryan/projects/famids/
If speed is of the essence you might want to use the script languages as prototypes and then build the final model in C.
badiane:
Pretty nice suggestions. As I'm also new to this topic (actually this thread made me to take a somehow deeper look into famd and how it works), I also appreciate to learn some other solutions (that's what I love on EE). Since I'm also learning ruby at the moment, I'm wondering, why I didn't have the idea to look for a fam ruby class. Bad mistake as one can see....;-)
So, many thanks for providing a new toy!

Regards,
-XoF-
Hello.. as far as I understand what your needs are... I think one way to have this sort of automatic backup is to create a raid-1 volume (the mirroring one). BTW the second disc will be automatically updated every time the main FS will change.

With this solution you don't need to write any code, use any crontab entry nor use find.

Hope this can help
Thanks for all your help all, but we went a different direction.  I am bookmarking this though if we ever visit this in the future.