Search code examples
pipelineapache-zookeepernetcat

why pipeline content to command nc won't work?


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?


Solution

  • 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.