rkrishnan
rkrishnan

Reputation: 806

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

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 /
[]

Upvotes: 12

Views: 55576

Answers (3)

jolestar
jolestar

Reputation: 1323

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

Upvotes: 19

Michelle Tan
Michelle Tan

Reputation: 395

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

Upvotes: 5

Giova
Giova

Reputation: 1127

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

Upvotes: 3

Related Questions