Issue
the command ads2 cls create
produces the following output:
cluster established ...
nodes {
node {
name = "fdt-c-agx-0002";
address = "http://172.16.11.89:9011/";
state = "3";
}
node {
name = "FDT-C-VM-0094";
address = "http://172.16.11.49:9011/";
state = "3";
}
}
What i'm trying to to is to find the name
of each node and its status, assign each to a variable and print them so that the output looks like:
NODE-1 name
has a state state
#This conforms to the first node
NODE-2 name
has a state state
#This conforms to the second node
So I started with grep like status-nod1="$(ads2 cls create | grep state | cut -d '"' -f 2)"
& name-nod1="$(ads2 cls create | grep name | cut -d '"' -f 2)"
.
This works, however finds all matches with state
and 'name' and thus returns
3
3
fdt-c-agx-0002
FDT-C-VM-0094
So How can i output the match in the write order so that each node matches its state
Solution
If you grep for both state and name, you'll get the details in order
ads2 cls create | grep '\(state\|name\) =' | cut -d '"' -f 2 \
| while read name status ; do ...
Answered By - choroba Answer Checked By - Dawn Plyler (WPSolving Volunteer)