- 论坛徽章:
- 0
|
[root@spocproxy ~]# ndb_mgm -e show
Connected to Management Server at: 192.168.2.4:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.2.4 (mysql-5.1.56 ndb-7.1.17, Nodegroup: 0, Master)
id=3 @192.168.2.5 (mysql-5.1.56 ndb-7.1.17, starting, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.2.4 (mysql-5.1.56 ndb-7.1.17)
[mysqld(API)] 4 node(s)
id=100 @192.168.2.4 (mysql-5.1.56 ndb-7.1.17)
id=101 @192.168.2.5 (mysql-5.1.56 ndb-7.1.17)
id=102 (not connected, accepting connect from any host)
id=103 (not connected, accepting connect from any host)
将以上输出格式化成下面格式
[
{"type":"ndbd","id":"2","hostname":"192.168.2.4"},
{"type":"ndbd","id":"3","hostname":"192.168.2.5"},
{"type":"ndb_mgmd","id":"1","hostname":"192.168.2.4"},
{"type":"mysqld","id":"100","hostname":"192.168.2.4"},
{"type":"mysqld","id":"101","hostname":"192.168.2.5"},
]
我现在的方法是:
ndb_mgm -c $connectstring -e show |sed -e '/mysqld(API)/,$!d' -e '/@[0-9].*/!d' -e 's/id=//;s/@//' |awk 'BEGIN {print "["};{printf ("{\"type\":\"mysqld\",\"id\":\"%s\",\"hostname\":\"%s\"},\n",$1,$2)};END {print "]"}'
ndb_mgm -c $connectstring -e show |sed -e '/ndbd(NDB)/,/ndb_mgmd/!d' -e '/@[0-9].*/!d' -e 's/id=//;s/@//'|awk 'BEGIN {print "["};{printf ("{\"type\":\"ndbd\",\"id\":\"%s\",\"hostname\":\"%s\"},\n",$1,$2)};END {print "]"}'
ndb_mgm -c $connectstring -e show |sed -e '/ndb_mgmd/,/mysqld(API)/!d' -e '/@[0-9].*/!d' -e 's/id=//;s/@//' |awk 'BEGIN {print "["};{printf ("{\"type\":\"ndb_mgmd\",\"id\":\"%s\",\"hostname\":\"%s\"},\n",$1,$2)};END {print "]"}'
分成三次去格式化,得到的结果是:
[
{"type":"ndbd","id":"2","hostname":"192.168.2.4"},
{"type":"ndbd","id":"3","hostname":"192.168.2.5"},
]
[
{"type":"ndb_mgmd","id":"1","hostname":"192.168.2.4"},
]
[
{"type":"mysqld","id":"100","hostname":"192.168.2.4"},
{"type":"mysqld","id":"101","hostname":"192.168.2.5"},
]
问题是如何通过一行命令得到我想要的结果
[
{"type":"ndbd","id":"2","hostname":"192.168.2.4"},
{"type":"ndbd","id":"3","hostname":"192.168.2.5"},
{"type":"ndb_mgmd","id":"1","hostname":"192.168.2.4"},
{"type":"mysqld","id":"100","hostname":"192.168.2.4"},
{"type":"mysqld","id":"101","hostname":"192.168.2.5"},
]
不使用shell脚本. 有兴趣的朋友可以研究下. |
|