Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 376
DiveInto Avatar asked Feb 18 '14 07:02

DiveInto


Video Answer


2 Answers

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.

like image 157
DiveInto Avatar answered Jan 03 '23 15:01

DiveInto


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.

like image 35
aj.esler Avatar answered Jan 03 '23 15:01

aj.esler