why pipeline content to command nc won't work?
Asked Answered
W

3

6

I try to get zookeeper stat from shell by using nc,

call nc localhost 2181 first, then type in: stat works.

while echo "stat" | nc localhost 2181 returns nothing.

why?

Witcher answered 18/2, 2014 at 7:11 Comment(0)
W
5

Asked the same question in Zookeeper mail list, and got this:

Most probably you are using the wrong "nc" command.

Not kidding :P there are two different "nc" packages, and the syntax is different betweem then. In debian-like distros they are netcat-openbsd and netcat-traditional, but I ran into the same problems with netcat in CentOS (I can't remember the name of the packages, sorry) until I realized I was using it wrong.

--Tomas Nunez

I found that the nc on my server is nc.openbsd, after install nc.traditional,

echo "stat" | nc.traditional 10.18.10.30 2181

returns the expected result.

Witcher answered 19/2, 2014 at 6:14 Comment(0)
F
4

I found that adding a wait with the -q param to the nc command resulted in the expected output.

echo "ruok" | nc -q 2 localhost 2181 worked for me on Ubuntu systems. You may need to use -w instead of -q on OpenBSD systems.

Fasten answered 4/8, 2014 at 23:42 Comment(0)
A
0

By default the whitelist only contains "srvr" command which zkServer.sh uses.

Try echo "srvr" | nc localhost 2181

or

set 4lw.commands.whitelist=*

see zookeeper doc 4lw.commands.whitelist

  • 4lw.commands.whitelist : (Java system property: zookeeper.4lw.commands.whitelist) New in 3.5.3: A list of comma separated Four Letter Words commands that user wants to use. A valid Four Letter Words command must be put in this list else ZooKeeper server will not enable the command. By default the whitelist only contains "srvr" command which zkServer.sh uses. The rest of four letter word commands are disabled by default. Here's an example of the configuration that enables stat, ruok, conf, and isro command while disabling the rest of Four Letter Words command:

4lw.commands.whitelist=stat, ruok, conf, isro

If you really need enable all four letter word commands by default, you can use the asterisk option so you don't have to include every command one by one in the list. As an example, this will enable all four letter word commands:

4lw.commands.whitelist=*

Three of the more interesting commands: "stat" gives some general information about the server and connected clients, while "srvr" and "cons" give extended details on server and connections respectively.

Moving forward, Four Letter Words will be deprecated, please use AdminServer instead.

The new method of AdminServer is setting 4lw.commands.whitelist=* and sending an HTTP request to http://localhost:8080/commands/stat using wget or curl.

root@zoo2:/apache-zookeeper-3.8.0-bin# wget --quiet --output-document=/dev/stdout http://localhost:8080/commands/stat
Abbasid answered 21/5, 2022 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.