views:

41

answers:

3

I have two servers, computer A and computer B, both running Linux. I need to write a program or a shell script which will continuously monitor the contents of my home directory on computer A and if anything changes, copy the changes to my home directory on computer B such that both home directories are always the same. (Any changes made to the home directory on computer B and safely be ignored.)

A: 

Use rsync, which will solve your problems. Most distributions would have this already pre-installed.

tommieb75
rsync doesn't do monitoring for changes in a directory, although I agree that it would be a good tool to use for the actual propagation. Ensuring that it happens immediately might be a little harder.
Darael
+4  A: 

Have you considered exporting /home from computer A to computer B via a network file system, e.g. NFS ?

You could also mount the exported filesystem on B in read-only mode so you won't be able to modify the contents of /home from B if that's desired.

Andre Holzner
+2  A: 

Assuming a reasonably recent Linux kernel (one including inotify - it's been present since 2.6.13), you could use inotify-tools as described here to monitor for changes and call rsync on the files to update computer B. That should do what you're asking for, and allow changes on B that don't propagate to A, as well.

You could probably do the same job with incron, which works like cron but based on filesystem events instead of times, but it seems more intended for use with single files.

Darael