onnode: fix get_nodes_with_status()
authorMartin Schwenke <martin@meltin.net>
Mon, 23 May 2011 05:24:52 +0000 (15:24 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 8 Jun 2011 04:23:40 +0000 (14:23 +1000)
Setting IFS and looping though items with colons in them doesn't work.
Change this to read through the output line by line.  The header line
needs to be thrown away by throwing away everything up to the 1st
newline.

Keep stderr from the "ctdb status" command, otherwise debugging is
impossible.

On error, append any output from ctdb to onnode's error message.

Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit d60592cf99999f10344a05ef0571fb300bb9d97c)

ctdb/tools/onnode

index 707294d5bd8af09d333d05010f521610d9ea90f7..59f2535d28466ff098e42e80e0320288646e0eda 100755 (executable)
@@ -139,21 +139,24 @@ get_nodes_with_status ()
     local status="$2"
 
     if [ -z "$ctdb_status_output" ] ; then
-       ctdb_status_output=$(ctdb -Y status 2>/dev/null)
+       ctdb_status_output=$(ctdb -Y status 2>&1)
        if [ $? -ne 0 ] ; then
            echo "${prog}: unable to get status of CTDB nodes" >&2
+           echo "$ctdb_status_output" >&2
            exit 1
        fi
-       ctdb_status_output="${ctdb_status_output#* }"
+       local nl="
+"
+       ctdb_status_output="${ctdb_status_output#*${nl}}"
     fi
 
     (
        local i
-       for i in $ctdb_status_output ; do
+       IFS="${IFS}:"
+       while IFS="" read i ; do
 
-           IFS="${IFS}:"
-           set -- $i
-           shift # line starts with : so 1st field is empty
+           set -- $i # split line on colons
+           shift     # line starts with : so 1st field is empty
            local pnn="$1" ; shift
            local ip="$1" ; shift
 
@@ -172,9 +175,9 @@ get_nodes_with_status ()
                *)
                    invalid_nodespec
            esac
-           
+
            echo_nth "$pnn" $all_nodes
-       done
+       done <<<"$ctdb_status_output"
     )
 }