From fe9477450a96d0e731126375b523b229088d2b1e Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Fri, 20 Jun 2014 09:45:00 +0200 Subject: theoretically it also works with directories now --- docs/netdiff.pod | 2 +- src/netdiff | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/docs/netdiff.pod b/docs/netdiff.pod index fa9fbb7..0408990 100644 --- a/docs/netdiff.pod +++ b/docs/netdiff.pod @@ -10,7 +10,7 @@ A simple script to diff two files via the network. ClusterSSH onto two hosts at the same time and run on both hosts the same command like: - netdiff HOSTNAME FILENAME + netdiff HOSTNAME PATH Where HOSTNAME can be the hostname of the first or the second host. Depending on this the script will decide to be the client or the server role. diff --git a/src/netdiff b/src/netdiff index 8c2d6b6..9bba61f 100755 --- a/src/netdiff +++ b/src/netdiff @@ -6,42 +6,48 @@ declare -r VERSION='VERSION_DEVEL' declare -i RC=0 -declare -r SERVER="${1}" ; shift -declare -r FILE="${1}" ; shift -declare -i PORT="${1}" ; shift +declare -r SERVER="${1}" ; shift +declare -r PATH="${1}" ; shift +declare -i PORT="${1}" ; shift usage () { cat < $TMPFILE +if [[ "${SERVER}" == "$(hostname)" || + "${SERVER}" == "$(hostname --fqdn)" ]]; then + tar -cf - . --directory "${PATH}" | + nc -l -p ${PORT} | + tar -xf - --directory ${TMPPATH} RC=$? else sleep 0.1 - nc ${SERVER} ${PORT} < "${FILE}" > $TMPFILE + tar -cf - . --directory "${PATH}" | + nc ${SERVER} ${PORT} | + tar -xf - --directory ${TMPPATH} RC=$? fi -if [ $RC -ne 0 ]; then +if [ ${RC} -ne 0 ]; then echo 'Could not copy file via the network' RC=2 # Default trouble exit status of diff else - diff $@ ${FILE} ${TMPFILE} ${DIFF_DEFAULT_OPTS} + diff $@ "${PATH}" ${TMPPATH} ${DIFF_DEFAULT_OPTS} RC=$? fi -[ -f $TMPFILE ] && rm $TMPFILE -exit $RC +[ -f ${TMPPATH} ] && rm -rf ${TMPPATH} +exit ${RC} -- cgit v1.2.3