changeset 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 2bde174fe9e2
children 580cc12c9712
files master/bin/internal/invoke.sh master/bin/wbash.sh master/bin/wrun.sh
diffstat 3 files changed, 44 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/master/bin/internal/invoke.sh	Mon Nov 19 18:31:21 2018 +0000
+++ b/master/bin/internal/invoke.sh	Mon Nov 19 18:32:30 2018 +0000
@@ -1,11 +1,20 @@
 #!/bin/bash
 # Helper for ../wrun, q.v.
-# Usage: invoke.sh [-x] me cmd ifile id port ip [args...]
+# 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
@@ -14,18 +23,18 @@
 if [ "$1" = "-x" ]
 then
  shift
- id=
+ tellid=
  me=
 else
  me=$1
- id=$4
+ tellid=$4
 fi
 cmd="$2"
 ifile=$3
 port=$5
 ip=$6
 shift 6
-echo "#$(date)#$cmd#$ifile#$id#$port#$ip#$@#" 1>&2
+echo "#$(date)#$cmd#$ifile#$tellid#$port#$ip#$@#" 1>&2
 if [ "$ifile" != "/dev/null" ]
 then
   echo "# from $ifile" 1>&2
@@ -33,8 +42,13 @@
 fi || echo scp failed, status=$? 1>&2
 if [ "$wait" ]
 then
-  ssh -tt -p $port $ip "nohup $cmd $id $me ""$@"" > nohup.cc"
+  cs="nohup $cmd $tellid $me "$@" > nohup.cc"
 else
-  ssh -p $port $ip "$cmd $id $me ""$@"
-fi || echo ssh failed, status=$? 1>&2
+  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
--- a/master/bin/wbash.sh	Mon Nov 19 18:31:21 2018 +0000
+++ b/master/bin/wbash.sh	Mon Nov 19 18:32:30 2018 +0000
@@ -2,16 +2,25 @@
 if [ $# -lt 1 ]
 then
   cat 1>&2 <<EOF
-Usage: cat cmds | $0 SSname [...args]
+Usage: cat cmds | $0 [-d] [-x] SSname [...args]
 Where SSname is the name of a VM scale set.
 
 Runs bash [with args] on every machine in a scale set,
  on commands from stdin
  by doing as it were
-  cat | ssh machine "bash \$args"
+  cat | ssh machine [$id] "bash \$args"
+
+if -d, show command eventually on stderr
 EOF
  exit 1
 fi
+if [ $1 = -d ]
+then
+ shift
+ debug=-d
+fi
 ss=$1
 shift
-wrun.sh $ss bash -x -ff - -i "$@" '\<ifile.txt'
+wrun.sh $ss '"bash -s"' $debug -ff - -i "$@" '\<ifile.txt'
+
+
--- a/master/bin/wrun.sh	Mon Nov 19 18:31:21 2018 +0000
+++ b/master/bin/wrun.sh	Mon Nov 19 18:32:30 2018 +0000
@@ -22,12 +22,17 @@
 name=$1
 cmd="$2"
 shift 2
+if [ "$1" = "-d" ]
+then
+ debug=-d
+ shift
+fi
 if [ "$1" = "-x" ]
 then
- id=-x
+ xx=-x
  shift
 else
- id=
+ xx=
 fi
 if [ "$1" = "-np" ]
 then
@@ -46,10 +51,7 @@
  file=$2
  shift 2
  tfile=$(mktemp)
- split -n r/$np -u --filter="cat > $tfile\$\$" $file &
- # Wait for files to be built
- while [ $np -gt $(ls ${tfile}* | wc -l) ]; do echo -n . 1>&2; sleep 1; done
- echo 1>&2
+ tee >(wc -l 1>&2) | split -n r/$np -u --filter="cat > $tfile\$\$" $file
  wc -l ${tfile}* 1>&2
 elif [ "$1" = "-ff" ]
 then
@@ -83,6 +85,6 @@
   while read i ip port
    do
     echo $i $port $ip
-   done) | \
- parallel --gnu --colsep ' ' -j $np "$(dirname "$0")"/internal/invoke.sh $wait $id $me "$cmd" {} "$@" || { r=$? ; echo parallel exited with status=$r 1>&2;}
-if [ "${tfile}" ]; then rm ${tfile}*; fi
+   done) | tee /tmp/test.txt | \
+ parallel --gnu --colsep ' ' -j $np "$(dirname "$0")"/internal/invoke.sh $debug $wait $xx $me "$cmd" {} "$@" || { r=$? ; echo parallel exited with status=$r 1>&2;}
+#if [ "${tfile}" ]; then rm ${tfile}*; fi