From d47e6cd1f5e7d8a855c68ac19271c6673681cffa Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Tue, 6 Sep 2016 22:36:15 -0400 Subject: [PATCH] really tasty addition of remote compares using ssh syntax, e.g. host:path notation. so now can compare like this: compare_dirs /z/musix surya:/z/musix to see what files are missing on one side or the other. --- scripts/files/compare_dirs.sh | 56 ++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/scripts/files/compare_dirs.sh b/scripts/files/compare_dirs.sh index ee1d69ae..cb538205 100644 --- a/scripts/files/compare_dirs.sh +++ b/scripts/files/compare_dirs.sh @@ -11,10 +11,10 @@ if [ -z "$dir1" -o -z "$dir2" ]; then echo list of differences in the two directory hierarchies. exit 1 fi -if [ ! -d "$dir1/" -o ! -d "$dir2/" ]; then - echo The directories to be compared must already exist. - exit 1 -fi +#if [ ! -d "$dir1/" -o ! -d "$dir2/" ]; then +# echo The directories to be compared must already exist. +# exit 1 +#fi if [ "$dir1" == "$dir2" ]; then echo "The two directories are the exact same folder name. So that's silly." exit 1 @@ -23,15 +23,51 @@ fi out1="$(mktemp "$TMP/compare_dirs_output.XXXXXX")" out2="$(mktemp "$TMP/compare_dirs_output.XXXXXX")" -pushd "$dir1" &>/dev/null -find . >"$out1" + + + +#hmmm: need error checking here!!!! + + + + + +if [[ $dir1 == *":"* ]]; then + # host processing on first dir. + host1=${dir1%:*} + dir1=${dir1#*:} +echo "got host1 as $host1" +echo "got new dir1 as $dir1" +fi +if [[ $dir2 == *":"* ]]; then + # host processing on second dir. + host2=${dir2%:*} + dir2=${dir2#*:} +echo "got host2 as $host2" +echo "got new dir2 as $dir2" +fi +if [ -z "$host1" ]; then + # fully local compare location for first dir. + pushd "$dir1" &>/dev/null + find . >"$out1" + popd &>/dev/null +else + # remote compare location for first dir. + ssh "$host1" "cd \"$dir1\" && find ." >"$out1" +fi +# sort the output from that find. sort "$out1" >"$out1".sort -popd &>/dev/null -pushd "$dir2" &>/dev/null -find . >"$out2" +if [ -z "$host2" ]; then + # fully local compare location for second dir. + pushd "$dir2" &>/dev/null + find . >"$out2" + popd &>/dev/null +else + # remote compare location for second dir. + ssh "$host2" "cd \"$dir2\" && find ." >"$out2" +fi sort "$out2" >"$out2".sort -popd &>/dev/null diff "$out1".sort "$out2".sort -- 2.34.1