Skip to content

Instantly share code, notes, and snippets.

@jhqv jhqv/rdiff.sh
Last active Oct 22, 2018

Embed
What would you like to do?
Remote diff file using SSH, useful for comparing config files when migrating services between machines etc.
#!/bin/bash
# Compare a local file with a remote file with (default) the same path or a custom path
# by Janek Hellqvist, 2016-10-14
# Example 1: compare same file on two different hosts
# rdiff.sh /etc/nginx/nginx.conf
# Example 2: compare local file with other remote file
# rdiff.sh /etc/nginx/conf.d/http.conf /etc/nginx/conf.d/www.conf
bold=$(tput bold)
normal=$(tput sgr0)
remoteuser="username"
remoteserver="123.123.123.123"
if [ -z $1 ]; then
echo "Usage: rdiff.sh <source file> <optional remote file>"
exit 1;
fi
file=`readlink -f $1` # get absolute path to file in case it was relative
if [ -z $2 ]; then
remotefile=$file
else
remotefile=$2
fi
if [ ! -f $file ]; then
echo "Local file $file not found!"
exit
fi
echo "Comparing local ${bold}$file${normal} (>) with remote ${bold}$remoteuser@$remoteserver:$remotefile${normal} (<)"
ssh $remoteuser@$remoteserver "cat $file" | diff - $file
@vaporup

This comment has been minimized.

Copy link

commented Sep 4, 2017

Thank you for this idea. I changed it a little bit and put it in ssh-diff https://github.com/vaporup/ssh-tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.