accessible by ssh, send required files, and get back result files
transparently.
-It creates a temporary files in /tmp/ on the remote host and runs
+It creates a temporary directory in /tmp/ on the remote host and runs
everything in it.
I use it mostly to launch heavy training with PyTorch on a PC at home.
function help () {
cat <<EOF
-xremote.sh [--help] [-h <remote_host>] [-i <remote_dir>] <script> [script arguments]
+xremote.sh [--help] [-h <remote_host>] [-d <remote_dir>] [-i] <script> [script arguments]
This script takes a script as argument and executes it remotely in a
temporary directory on a ssh-accessible server.
If the -h option is provided @XREMOTE_HOST is ignored.
+ If the -d option is provided, the provided directory is used and
+ kept, instead of a temporary one
+
If the -i option is provided, all the files are installed and
scripts run in the specified directory on the remote host, but the
main executable and post-run commands are ignored
}
function cleanup_remote_tmp () {
- if [[ "${REMOTE_HOST}" ]] && [[ "${REMOTE_DIR}" ]] && [[ ! "${ARG_DIR}" ]]
+ if [[ "${REMOTE_HOST}" ]] && [[ "${REMOTE_DIR}" ]]
then
- echo "xremote: Clean up remote workdir."
+ if [[ "${ARG_DIR}" ]]
+ then
+ echo "xremote: Keeping remote workdir."
+ else
+ echo "xremote: Cleaning up temporary remote workdir."
+ ssh "${REMOTE_HOST}" rm -rf "${REMOTE_DIR}"
+ fi
fi
}
echo "xremote: remote forced to ${ARG_HOST}"
;;
- -i)
+ -d)
shift
ARG_DIR="$1"
[[ ${ARG_DIR} ]] || (echo "xremote: Directory missing." && exit 1)
echo "xremote: remote dir set to ${ARG_DIR}"
;;
+ -i)
+ NO_RUN=1
+ echo "xremote: no run"
+ ;;
+
--help)
help
exit 0
tar c "${main}" | ssh "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && tar mx"
-if [[ "${ARG_DIR}" ]]
+if [[ "${NO_RUN}" ]]
then
echo "xremote: everything has been set up in ${REMOTE_HOST}:${ARG_DIR}"
exit 0