Support Questions

Find answers, ask questions, and share your expertise

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

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


Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.