Expert Contributor
Posts: 121
Registered: ‎08-08-2013

get Zookeeper data from bash, via zookeeper-client



I need to retrieve data from a znode within a bash script, using a zookeeper-client call , like

zookeeper-client -server zk0001,zk0002:2181 get /my/test



the output is much too verbose and I wanted to know if there is a way to remove that 'noise' and just get the pure data itself.

From all that output:

2017-03-15 15:58:29,754 [myid:] - INFO [main-SendThread(zk0002:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server usdprz0002:2181, sessionid = 0x35992303028a771, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null 1489589100000 cZxid = 0x11001d4d72 ctime = Wed Mar 15 15:58:18 CET 2017 mZxid = 0x11001d4d72 mtime = Wed Mar 15 15:58:18 CET 2017 pZxid = 0x11001d4d72 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 13 numChildren = 0

I am just interested in:


Any help appreciated, thanks.

Expert Contributor
Posts: 101
Registered: ‎01-24-2014

Re: get Zookeeper data from bash, via zookeeper-client

Not exactly elegant, but a simple grep could get that for you (it would not be resilient to change in zookeeper output)



zookeeper-client -server zk0001,zk0002:2181 get /my/test | grep -B 1 cZxid | grep -v cZxid