projects
/
xremote.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c22bc09
)
Added the -h option to force the remote host
author
Francois Fleuret
<francois@fleuret.org>
Wed, 4 Jul 2018 18:30:58 +0000
(20:30 +0200)
committer
Francois Fleuret
<francois@fleuret.org>
Wed, 4 Jul 2018 18:30:58 +0000
(20:30 +0200)
xremote.sh
patch
|
blob
|
history
diff --git
a/xremote.sh
b/xremote.sh
index
c093b62
..
7556470
100755
(executable)
--- a/
xremote.sh
+++ b/
xremote.sh
@@
-35,12
+35,12
@@
function check_remote_is_defined () {
function help () {
cat <<EOF
function help () {
cat <<EOF
-xremote.sh
<script> [
arguments]
+xremote.sh
[-h remote_host] <script> [script
arguments]
This script takes a script as argument and executes it remotely in a
temporary directory on a ssh-accessible server.
This script takes a script as argument and executes it remotely in a
temporary directory on a ssh-accessible server.
- It parses the script first to find embedded arguments which define
s
+ It parses the script first to find embedded arguments which define
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.
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.
@@
-56,8
+56,11
@@
xremote.sh <script> [arguments]
@XREMOTE_GET: *.dat
@XREMOTE_PRE: ln -s /home/fleuret/data/pytorch ./data
@XREMOTE_GET: *.dat
@XREMOTE_PRE: ln -s /home/fleuret/data/pytorch ./data
- If no argument is provided to @XREMOTE_HOST, the environment
- variable \$XREMOTE_HOST is used instead
+ If the -h option is provided @XREMOTE_HOST is ignored.
+
+ If no argument is provided to @XREMOTE_HOST, and the -h option is
+ not specified, the environment variable \$XREMOTE_HOST is used
+ instead
Contact <francois@fleuret.org> for comments.
Contact <francois@fleuret.org> for comments.
@@
-75,7
+78,26
@@
function cleanup_remote_tmp () {
######################################################################
######################################################################
-[[ -x "$1" ]] || (help && exit 1)
+while [[ "$1" =~ ^- ]]
+do
+ case "$1"
+ in
+ -h)
+ shift
+ ARG_HOST="$1"
+ echo "xremote: remote forced to ${ARG_HOST}"
+ ;;
+ *)
+ echo "Unknown option $1"
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+######################################################################
+
+[[ -a "$1" ]] || (help && exit 1)
main="$(basename "$1")"
main="$(basename "$1")"
@@
-118,7
+140,8
@@
do
HOST)
[[ "${REMOTE_DIR}" ]] && (exit "Remote host already defined!" >&2 && exit 1)
HOST)
[[ "${REMOTE_DIR}" ]] && (exit "Remote host already defined!" >&2 && exit 1)
- REMOTE_HOST="${value}"
+ REMOTE_HOST="${ARG_HOST}" # Host given in argument has priority
+ [[ "${REMOTE_HOST}" ]] || REMOTE_HOST="${value}"
[[ "${REMOTE_HOST}" ]] || REMOTE_HOST="${XREMOTE_HOST}"
[[ "${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)"
[[ "${REMOTE_HOST}" ]] || REMOTE_HOST="${XREMOTE_HOST}"
[[ "${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)"
@@
-169,6
+192,12
@@
do
label=$(echo "${line}" | sed -e 's/^.*@XREMOTE_\([^:]*\):.*$/\1/')
value=$(echo "${line}" | sed -e 's/^.*@XREMOTE_[^:]*: *\(.*\)$/\1/')
case "${label}" in
label=$(echo "${line}" | sed -e 's/^.*@XREMOTE_\([^:]*\):.*$/\1/')
value=$(echo "${line}" | sed -e 's/^.*@XREMOTE_[^:]*: *\(.*\)$/\1/')
case "${label}" in
+ POST)
+ check_remote_is_defined
+ echo "xremote: ${value}"
+ ssh < /dev/null "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && ${value}"
+ ;;
+
GET)
check_remote_is_defined
ssh </dev/null "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && tar 2>/dev/null c ${value}" | tar mxv
GET)
check_remote_is_defined
ssh </dev/null "${REMOTE_HOST}" "cd \"${REMOTE_DIR}\" && tar 2>/dev/null c ${value}" | tar mxv