Duplicate input unix stream to multiple TCP clients (using socat)

6.3k views Asked by At

I have a syslog server which writes to a unix stream /tmp/syslog.socket. I need to duplicate this stream to multiple TCP clients. Is there a way to achieve this using socat?

2

There are 2 answers

1
Vorsprung On

syslogd has a facility for redistributing the logs via udp, see the man page for syslogd, ie

http://linux.about.com/od/commands/l/blcmdl8_syslogd.htm

I believe that syslog-ng also supports tcp sockets for log redistrubution as well as udp

http://www.syslog.org/syslog-ng/v2/

I would guess that you don't need a hack with socat?

1
lkraav On

I think I just accomplished this, especially the duplicating part, with the help of Some Helpful socat Commands.

socat TCP-LISTEN:4444,reuseaddr,fork SYSTEM:"tail -f ~/.tail-error-logs/*",pty

fork is important on the left side, pty is important on the right side.

What didn't work, was netcat style:

tail -f ~/.tail-error-logs/* | socat STDIO TCP-LISTEN:4444,fork,reuseaddr

It had the effect of output alternating between multiple attached clients, which is also documented on above website.