Last active
October 22, 2018 02:31
Remote diff file using SSH, useful for comparing config files when migrating services between machines etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this idea. I changed it a little bit and put it in ssh-diff https://github.com/vaporup/ssh-tools