Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to send a small string to statsd via nc inside of a read block:

while read line; do
    printf "folder.counter:value|1c" | nc -q 0 -u $host $port

Unfortunately, when in UDP mode, nc seems to want to wait indefinitely, even though I've specified -q 0, which the man page says will make the program exit immediately after EOF.

I've tried passing -w 1, but if the data I'm sending comes in at more than one line per second, the data buffers up, and I lose my real time stats (not to mention risking a buffer overflow of some sort).

Is it possible to do what I'm trying to do with netcat, or am I going to need to write something in language which has a statsd library?

share|improve this question
although it didn't solve yours, adding -q 0 solved my issue – Colin Apr 2 at 16:49
up vote 5 down vote accepted

I ended up fixing the problem by switching to socat:

while read line; do
    printf "folder.counter:value|1c" | socat -t 0 - UDP:$host:$port
share|improve this answer
As there's been no other input, and this resolved my problem, I'm marking it as the answer. – bshacklett Apr 15 '13 at 13:05

You can specify 0 as a timeout value to -w, so it won't wait at all.

share|improve this answer

adding -v option solved my issue. The reason I am not sure.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.