view master/bin/internal/invoke.sh @ 30:9275e2a8b5e2

hacking to get id into wbash.sh, maybe buggy?
author Henry S. Thompson <ht@markup.co.uk>
date Mon, 19 Nov 2018 18:32:30 +0000
parents 2fbefb8d1a9e
children
line wrap: on
line source

#!/bin/bash
# Helper for ../wrun, q.v.
# Usage: invoke.sh [-d] [-w] [-x] me cmd ifile id port ip [args...]
#  Runs 
#   cmd [id] args...
#  via ssh to ip:port
#  If ifile is not /dev/null, feed in as stdin
#  If -d, echo command line to stderr
#  If -w, wrap command in nohup and wait for result
#  Unless -x, worker id is passed as first arg
echo $@ 1>&2
echo "$@" 1>&2
if [ "$1" = "-d" ]
then
 shift
 debug=1
fi
if [ "$1" = "-w" ]
then
 shift
 wait=1
fi
if [ "$1" = "-x" ]
then
 shift
 tellid=
 me=
else
 me=$1
 tellid=$4
fi
cmd="$2"
ifile=$3
port=$5
ip=$6
shift 6
echo "#$(date)#$cmd#$ifile#$tellid#$port#$ip#$@#" 1>&2
if [ "$ifile" != "/dev/null" ]
then
  echo "# from $ifile" 1>&2
  scp -P $port $ifile $ip:ifile.txt
fi || echo scp failed, status=$? 1>&2
if [ "$wait" ]
then
  cs="nohup $cmd $tellid $me "$@" > nohup.cc"
else
  cs="$cmd $tellid $me ""$@"
fi
if [ "$debug" ]
then
 echo ssh -tt -p $port $ip $cs 1>&2
fi
ssh -tt -p $port $ip "$cs" || echo ssh failed, status=$? 1>&2
echo "#$(date)#$id#" 1>&2