How to run zookeeper zkCli.sh commands from bash?

Is it possible to run the zkCli.sh ls / as ls / or get / from bash directly without going into the zookeeper shell? I am using Zookeeper version 3.4.6-1569965.

For example, something like this:

 $ ./zkCli.sh get / 

I can only do this after connecting to the zookeeper shell and then running get / from there, as shown below:

 $ ./zkCli.sh Connecting to localhost:2181 Welcome to ZooKeeper! WATCHER:: WatchedEvent state:AuthFailed type:None path:null JLine support is enabled WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0] get / [] 
+5
source share
3 answers

zkCli.sh are the process support commands after 3.4.7. https://issues.apache.org/jira/browse/ZOOKEEPER-1897

eg:

 ./zkCli.sh -server xxxxx:2181 get /test 

zkcli, golang cli for zookeeper, https://github.com/go-zkcli/zkcli , is also a simple solution.

 zkcli --servers srv-1,srv-2,srv-3 create /demo_only some_value 
+6
source

you can use bash without going directly. However, the only drawback to this is that you have to make sure your zk command / syntax is correct.

This will work:

 #! /bin/bash zkCli.sh -server localhost:2181 <<EOF get /testnode quit EOF 

But it will not be:

 #! /bin/bash zkCli.sh -server localhost:2181 <<EOF gt /testnode quit EOF 
+3
source

I can get the HBase Master address, for example, with the following syntax:

zkCli.sh -server myserver get /hbase/master If this does not work, the other will be:

 zkCli.sh -server myserver <<EOF get /hbase/master 

quit

EOF

+1
source

Source: https://habr.com/ru/post/1240493/


All Articles