Ruby File Monitor of an NFS mount (Can't use iNotify) - ruby

I need to find another way to monitor a directory recursively on an NFS mount on linux box.
Polling seems to be my only option. Any others? Is there a file monitor in ruby that doesn't use inotify?
Inotify requires the kernel and an nfs mount has the limitation that it cannot work over networked file system mounts.
Thanks for any ideas.
edit: This is to be used in my code, not a stand-alone command line tool.

Ara Howard's dirwatch might be a good fit for you. I don't believe it uses iNotify
http://codeforpeople.com/lib/ruby/dirwatch/dirwatch-0.9.0/README

Related

Unix Shell script to monitor a folder for files with user details

I have below requirement where I want to monitor a folder for file activity and user who is doing that.
I know something call inotify tools but will that work on all unix versions like HP, Solaris etc?
And how to track name of user/id who doing that file add/delete/modify?
I know something call inotify tools but will that work on all unix
versions like HP, Solaris etc?
inotify is a Linux-only solution. There are approximately similar solutions available for other operating systems (e.g., Solaris has file event notifications, but I don't know that there is anything available that wraps them up in a single API.
And how to track name of user/id who doing that file add/delete/modify?
You can't, at least not in a cross-platform manner. Under Linux you can probably accomplish a task like this using the audit subsystem, but that is again a Linux-only solution.

How does Mac OS X know what programs are using a mounted filesystem?

This may sound like a silly question but up until recently if you tried to unmount a volume that was in use the Finder reported that it was in use, but not by whom. This is simple Unix functionality, if a file is open on a mount point, do not allow it to eject. But now they seem to have added functionality that lets the user know what programs are currently using a mounted system, and I have been looking through man pages of fopen,stat, etc. for Unix like operating systems(distros of linux) and I can't seem to find similar functionality.
Is this functionality specialized, or am I just looking in the wrong place?
There are BSD-level calls (mainly lsof, whose source is at http://www.opensource.apple.com/source/lsof/) that let you examine the list of files open in a process. Activity Monitor, for example, uses them.
Using lsof as a starting point, you can iterate through processes and see if any of them are using a file under the mount point you're examining. There may be more efficient ways to do it though, of which I'm not aware. :)
It's somewhat specialized. Check out the lsof utility.
Check the man page for fuser, and run fuser -c /mountpoint

how to map a software as a Drive?

I am trying to create a software like Ibackup.com. However, I am not sure how to make the software so that it'll map as a local Harddrive. And i am not sure where to start researching on this. Someone please give me some pointers.
I can point you to Dokan ( a user filesystem for windows like FUSE on linux), You install the driver then write the appropriate software for replying on IO request.
On a more complex answer you have to work with the NT DDK to write a driver that would be your software for being a filesystem (look at IFS: installable file system ), note that it is very complicated to work with (mainly because a crash of your software mean a BSOD ), and you would probably like some more higher level software like Dokan that would help you in that regard.
You need to write a device driver implementing an Installable Filesystem (IFS).
I personally haven't done this but here's a piece of software I know that mounts Linux (ext2/3/4) filesystem on Windows: Ext2IFS.
And here's the SDK from Microsoft: IFS Kit
Take a look at the Subst command. I suggest you invoke it externally instead of simulating what it does, simply because of all the things that can go wrong.
(Side note: The correct term is a volume, not a drive.)
Just as a reference: virtual drives can be created using our Callback File System product, which is a supported, documented and maintained solution.

Where is data on a non-persistant Live CD stored?

When I boot up Linux Mint from a Live CD, I am able to save files to the "File System". But where are these files being saved to? Can't be the disc, since it's a CDR. I don't think it's stored in the RAM, because it can only hold so much data and isn't really intended to be used as a "hard drive". The only other option is the hard drive... but it's certainly not saving to any partition on the hard drive I know about, since none of them are mounted. Then where are my files being saved to??
Believe it or not, it's a ramdisk :)
All live distros mount a temporary hard disk in RAM memory. The process is completely user-transparent and is all because of the magic of Linux kernel.
The OS, in fact, first allocates an area of your RAM memory into a virtual device, then mounts it as a regular hard drive in your file system.
Once you reboot, you lose all your data from that ramdrive.
Ramdrive is needed by almost all software running on Live CDs. In fact, almost all programs, in particular desktop managers, are designed in order to write files, even temporary, during their execution.
As an example, there are two ways to run KDE on a Live CD: either modify its code deeply in order to disallow you to change wallpaper etc. (the desktop settings are stored inside ~/.kde) or redeploy it onto a writable file system such as a ramdrive in order to avoid write fails on read-only file systems.
Obviously, you can mount your real HDD or any USB drive into your virtual file system and make all writes to them permanent, but by default no live distro mounts your drives into the root file system, instead they usually mount into specific subdirectories like /mnt, /media, /windows
Hope to have been of help.
It does indeed emulate a disk using RAM; from Wikipedia:
It is able to run without permanent
installation by placing the files that
typically would be stored on a hard
drive into RAM, typically in a RAM
disk, though this does cut down on the
RAM available to applications.
RAM. In Linux, and indeed most unix systems, any kind of device is seen as a file system.
For example, to get memory info on linux you use cat /proc/meminfo, where cat is used to read files. Then, there's all sorts of strange stuff like /dev/random (to read random crap) and /dev/null (to throw away crap). ;-)
To make it persistent - use a USB device - properly formatted and with a special name. See here:
https://help.ubuntu.com/community/LiveCD/Persistence

Is there a way to hook into the windows file system so that for a particular directory I controlled every bit with custom code?

I'm interested to know if there's any method/mechanism to roll my own virtual file system that will run on modern windows. The idea would be that no matter what part of the operating system tried to access files under the directory I "control", all of the operations are filtered through some kind of callback code. If not, is there a fundamental reason why?
You absolutely can do this, it's called a "reparse point". See MSDN for the details.
Eugene is correct... you want to look at the documentation for File System Filters, not for reparse points.
Take a look at the TrueCrypt source code its open source and it does something very close to what you want: "# Creates a virtual encrypted disk within a file and mounts it as a real disk."

Resources