Monday, October 23, 2006

Comparing directories on two machines

Every once in a while you need to compare a bunch of files between two machines (e.g. when you have a directory replicated between two servers ... but not using rsync ..).

Here's a quick and easy way to do it (all commands running on machine2 as user1):
[user1@machine2]$ cd /home/user1/src
[user1@machine2]$ ssh user1@machine1 "cd src; find . -type f -exec md5sum {} \;" | md5sum --check | grep -v "OK"

basically, we are ssh-ing into the secondary machine, creating a list of files and running md5 on them, and then using that list as input for the local directory.
Clearly, you can change the find parameters for specific files, and also add gzip in the pipe if the list is very long or the connection is slow.

fun fun fun!

No comments: