Technomancy

Entries tagged “script”

Script to do a directory diff of a local directory and remote directory.

written by rory, on Sep 17, 2009 1:35:00 PM.

diff can do a directory diff, where it will tell you all the differences from one directory to another. rsync will compare 2 directories and tell you what files are different, but it won't tell you what the differences are. I combined both into this script so I could get a diff of a local directory and a remote directory.

Usage

Call it like this:
./dirdiff.sh /path/to/local/directory name.of.remotemachine.com /path/to/remote/directory
#! /bin/bash

LOCALDIR=$1
REMOTEHOST=$2
REMOTEDIR=$3

rsync -vrn "$LOCALDIR" ${REMOTEHOST}:"${REMOTEDIR}" 2>/dev/null | sed '1d' | head --lines=-3 | while read file ; do
    diff -u "$file" <(ssh $REMOTEHOST cat "$REMOTEDIR/$file" 2>/dev/null)
done