I was playing around with awk, and I wanted to expose it over a tcp socket.
At first I tried, but failed with micro-inetd. Thinking that maybe the issue could be in the way that carriage returns/newlines characters are handled, I decided to try to switch to socat.
Using a remote command with socat is easy enough:
socat TCP4-LISTEN:9000 EXEC:/bin/cat
socat TCP4-LISTEN:9000 SYSTEM:"/bin/python -i"
both of these work
But when trying the same with a simple awk command (for example `awk '{print NR}' to progressively count the number of lines received) I don't get anything back when connecting with socat from another shell on the same machine.
I tried plenty of things (some of these fail with a syntax error that is a bit obscure to me. I cannot even try to strace socat to see what exactly is being executed, since the actual command exec'ing is delegated to the shell):
socat TCP4-LISTEN:9000 SYSTEM:"/usr/bin/awk '{print NR}'"
socat TCP4-LISTEN:9000 SYSTEM:'/usr/bin/awk "{print NR}"'
socat TCP4-LISTEN:9000 SYSTEM:'/usr/bin/awk "{print\ NR}"'
I also created a small script /tmp/testawk
#! /bin/sh
/usr/bin/awk '{print NR}'
(also with an exec variant)
#! /bin/sh
exec /usr/bin/awk '{print NR}'
Both of these work locally, but when invoking
socat TCP4-LISTEN:9000 EXEC:/tmp/testawk
It doesn't send me back the output
Thinking that the issue might be inheritance of the stdin/stdout handles and/or again handling of crlf... I tried also with:
socat TCP4-LISTEN:9000 EXEC:/tmp/testawk,nofork
socat TCP4-LISTEN:9000,crnl EXEC:/tmp/testawk
socat TCP4-LISTEN:9000 EXEC:/tmp/testawk,crnl
socat TCP4-LISTEN:9000,crnl EXEC:/tmp/testawk,crnl
I've found someone else who complained about a similar issue, but apparently it failed to garner any attention
Any idea on what is going wrong?
stdbuf -oL -eL /usr/bin/awk '{print NRq}'
but I still cannot see anything from the other side – berdario Feb 20 '15 at 18:13pty
option apparently was what I was looking for: http://stackoverflow.com/questions/6344501/make-socat-write-to-tcp-or-unix-socket-line-by-line-for-log-gathering – berdario Feb 20 '15 at 18:24