Minor update.
[xremote.git] / xremote.sh
index da23287..d425792 100755 (executable)
@@ -40,8 +40,8 @@ xremote.sh <script>
   temporary directory on a ssh-accessible server.
 
   It parses the script first to find embedded arguments which defines
   temporary directory on a ssh-accessible server.
 
   It parses the script first to find embedded arguments which defines
-  the hostname on which to run it, the files to send, the files to
-  get back when the execution is done, and commands to execute before
+  the hostname on which to run, the files to send, the files to get
+  back when the execution is over, and commands to execute before
   running the executable remotely.
 
   These arguments can appear multiple times, except the one that
   running the executable remotely.
 
   These arguments can appear multiple times, except the one that
@@ -67,7 +67,7 @@ EOF
 function cleanup_remote_tmp () {
     if [[ "${REMOTE_HOST}" ]] && [[ "${REMOTE_DIR}" ]]
     then
 function cleanup_remote_tmp () {
     if [[ "${REMOTE_HOST}" ]] && [[ "${REMOTE_DIR}" ]]
     then
-        echo "Clean up remote workdir."
+        echo "xremote: Clean up remote workdir."
         ssh "${REMOTE_HOST}" "rm -rf \"${REMOTE_DIR}\""
     fi
 }
         ssh "${REMOTE_HOST}" "rm -rf \"${REMOTE_DIR}\""
     fi
 }
@@ -97,6 +97,7 @@ do
 
             EXEC)
                 check_remote_is_defined
 
             EXEC)
                 check_remote_is_defined
+                [[ "${REMOTE_EXEC}" ]] && (exit "Remote executable already defined!" >&2 && exit 1)
                 REMOTE_EXEC="${value}"
                 ;;
 
                 REMOTE_EXEC="${value}"
                 ;;
 
@@ -107,15 +108,15 @@ do
 
             SEND)
                 check_remote_is_defined
 
             SEND)
                 check_remote_is_defined
-                tar c "${value}" | ssh "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && tar mx"
+                tar c ${value} | ssh "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && tar mx"
                 ;;
 
             HOST)
                 [[ "${REMOTE_DIR}" ]] && (exit "Remote host already defined!" >&2 && exit 1)
                 REMOTE_HOST="${value}"
                 [[ "${REMOTE_HOST}" ]] || REMOTE_HOST="${XREMOTE_HOST}"
                 ;;
 
             HOST)
                 [[ "${REMOTE_DIR}" ]] && (exit "Remote host already defined!" >&2 && exit 1)
                 REMOTE_HOST="${value}"
                 [[ "${REMOTE_HOST}" ]] || REMOTE_HOST="${XREMOTE_HOST}"
-                [[ "${REMOTE_HOST}" ]] || (echo "No remote host specified." >&2 && exit 1)
-                REMOTE_DIR="$(ssh </dev/null "${REMOTE_HOST}" mktemp -d /tmp/xremote.from_"$(hostname)_$(date +%Y%m%d)".XXXXXX)"
+                [[ "${REMOTE_HOST}" ]] || (echo "xremote: No remote host specified." >&2 && exit 1)
+                REMOTE_DIR="$(ssh </dev/null "${REMOTE_HOST}" mktemp -d /tmp/xremote.from_"$(hostname)_$(date +%Y%m%d-%H%M%S)".XXXXXX)"
                 ;;
         esac
     fi
                 ;;
         esac
     fi
@@ -128,7 +129,7 @@ check_remote_is_defined
 
 tar c "${main}" | ssh "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && tar mx"
 
 
 tar c "${main}" | ssh "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && tar mx"
 
-echo "On ${REMOTE_HOST}"
+echo "xremote: on ${REMOTE_HOST}"
 
 if [[ "${REMOTE_EXEC}" ]]
 then
 
 if [[ "${REMOTE_EXEC}" ]]
 then
@@ -137,13 +138,15 @@ else
     REMOTE_COMMAND="./${main}"
 fi
 
     REMOTE_COMMAND="./${main}"
 fi
 
+echo "xremote: -- stdout ---------------------------------------------------"
 ssh </dev/null "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && ${REMOTE_COMMAND}"
 ssh </dev/null "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && ${REMOTE_COMMAND}"
-echo "----------------------------------------------------------------------"
 
 ######################################################################
 
 # Disable globbing to keep wildcards for the remote side
 
 
 ######################################################################
 
 # Disable globbing to keep wildcards for the remote side
 
+echo "xremote: -- retrieve results -----------------------------------------"
+
 set -f
 
 while read line
 set -f
 
 while read line
@@ -155,7 +158,7 @@ do
         case "${label}" in
             GET)
                 check_remote_is_defined
         case "${label}" in
             GET)
                 check_remote_is_defined
-                ssh </dev/null "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && tar c ${value}" | tar mxv
+                ssh </dev/null "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && tar 2>/dev/null c ${value}" | tar mxv
                 ;;
         esac
     fi
                 ;;
         esac
     fi
@@ -163,4 +166,6 @@ done < "${main}"
 
 set +f
 
 
 set +f
 
+echo "xremote: -- finished -------------------------------------------------"
+
 ######################################################################
 ######################################################################