How can I run ZooKeeper's zkCli.sh commands from Bash?
Asked Answered
G

3

12

Is it possible to run a zkCli.sh command, like ls / or get /, from Bash directly without going inside the ZooKeeper shell?

I am using ZooKeeper version 3.4.6-1569965.

For example, something like this:

$ ./zkCli.sh get /

I am able to do this only after connecting to the ZooKeeper shell and then running get / from there, like 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 /
[]
Guatemala answered 13/1, 2016 at 1:33 Comment(2)
Have you tried ./zkCli.sh -cmd "get /"Protractile
where can I find zkcli on my host ?Sypher
E
19

zkCli.sh has supported process commands since version 3.4.7.

See ZK Shell/Cli not processing commands

Such as:

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

zkcli, a Go command-line interface for ZooKeeper is also a simple solution.

zkcli --servers srv-1,srv-2,srv-3 create /demo_only some_value
Emissivity answered 12/11, 2016 at 16:26 Comment(0)
I
5

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

This would work:

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

But this won't:

#! /bin/bash
zkCli.sh -server localhost:2181 <<EOF
gt /testnode
quit
EOF
Impact answered 13/6, 2016 at 9:54 Comment(0)
D
3

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

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

zkCli.sh -server myserver <<EOF
get /hbase/master
quit
EOF
Dapple answered 13/1, 2016 at 10:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.