ctdb-onnode: New -i option to stop stdin from being closed
authorMartin Schwenke <martin@meltin.net>
Wed, 13 Nov 2013 03:04:17 +0000 (14:04 +1100)
committerMichael Adam <obnox@samba.org>
Wed, 27 Nov 2013 17:46:16 +0000 (18:46 +0100)
This can be useful for piping data to onnode in certain circumstances.

There are now also enough command-line options that they should
definitely be alphabetically ordered.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Michael Adam <obnox@samba.org>
ctdb/doc/onnode.1.xml
ctdb/tools/onnode

index 561764c1f0e6acc27bad203179fe99ca88f00320..ec878031633652b96a6d9d8eef41e005be68f23f 100644 (file)
         </listitem>
       </varlistentry>
 
+      <varlistentry><term>-i</term>
+        <listitem>
+          <para>
+           Keep standard input open, allowing data to be piped to
+           onnode.  Normally onnode closes stdin to avoid surprises
+           when scripting.  Note that this option is ignored when
+           using <option>-p</option> or if <envar>SSH</envar> is set
+           to anything other than "ssh".
+         </para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry><term>-n</term>
         <listitem>
           <para>
index 0abc13636ef663f0157710f16a88c9282a9c1b34..33d0e20779d96682e0d947db48a617c65d05c169 100755 (executable)
@@ -31,13 +31,14 @@ usage ()
 Usage: onnode [OPTION] ... <NODES> <COMMAND> ...
   options:
     -c          Run in current working directory on specified nodes.
+    -f          Specify nodes file, overrides CTDB_NODES_FILE.
+    -i          Keep standard input open - the default is to close it.
+    -n          Allow nodes to be specified by name.
     -o <prefix> Save standard output from each node to file <prefix>.<ip>
     -p          Run command in parallel on specified nodes.
+    -P          Push given files to nodes instead of running commands.
     -q          Do not print node addresses (overrides -v).
-    -n          Allow nodes to be specified by name.
-    -f          Specify nodes file, overrides CTDB_NODES_FILE.
     -v          Print node address even for a single node.
-    -P          Push given files to nodes instead of running commands.
   <NODES>       "all", "any", "ok" (or "healthy"), "con" (or "connected"),
                 "rm" (or "recmaster"), "lvs" (or "lvsmaster"),
                 "natgw" (or "natgwlist"); or
@@ -64,6 +65,7 @@ quiet=false
 prefix=""
 names_ok=false
 push=false
+stdin=false
 
 ctdb_base="${CTDB_BASE:-/etc/ctdb}"
 
@@ -74,7 +76,7 @@ parse_options ()
     # options ot onnode.
     local temp
     # Not on the previous line - local returns 0!
-    temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cf:hno:pqvP" -l help -- "$@")
+    temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cf:hno:pqvPi" -l help -- "$@")
 
     [ $? != 0 ] && usage
 
@@ -90,6 +92,7 @@ parse_options ()
            -q) quiet=true ; shift ;;
            -v) verbose=true ; shift ;;
            -P) push=true ; shift ;;
+           -i) stdin=true ; shift ;;
            --) shift ; break ;;
            -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable.
        esac
@@ -367,7 +370,9 @@ else
        [ -r "${ctdb_base}/onnode.conf" ] && . "${ctdb_base}/onnode.conf"
        [ -n "$SSH" ] || SSH=ssh
        if [ "$SSH" = "ssh" ] ; then
-           ssh_opts="-n"
+           if $parallel || ! $stdin ; then
+               ssh_opts="-n"
+           fi
        else
            : # rsh? All bets are off!
        fi