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!

Friday, October 13, 2006

The amazing screen utility

How many times did you start something in an SSH session and then really needed to leave, and wanted to attach to it from somewhere else.
The answer has been around in shell for years. Once I got used to it, I can never live without screen.
Read the man page .. but in short, screen lets you create sessions and then detach from them and reattach from somewhere else.

To create a screen session run:
or, you can also : screen -dR (which tries to reattach to an existing session or run a new one).

To detach type : ctrl-A d

To reattach type : screen -r (potentiallty add the session id if there are more than one)

To see a list of sessions : screen -ls
you can specify a specific terminal if there are a few when reattaching.

fun fun fun !