It seems the purpose of the first command is just to append data to /out_socat.txt
. socat
with fork
can handle multiple incoming connections even if they happen in parallel. Parallel appending to a file may cause streams to be written as interleaved, so this only makes sense if received streams are short (so there is high chance that each gets to the file in one atomic act of writing) or if connections happen one after another.
The second command pipes data to wmbusmeters …
. Your nc -k
can handle multiple incoming connections; but just one at a time, not in parallel. Incoming data from these multiple connections will be concatenated and processed by a single instance of wmbusmeters …
.
There is a way to make two or more processes listen on the same port, so an incoming connection will be passed to a process that is idle at the time. Still it's one connection to one listener. I think you want each connection to be processed by your both commands.
In general this may be tricky, but in your particular case there are circumstances that make this easy:
- You just receive, you don't send anything back.
- One of the commands just appends everything to a file.
- You don't need to handle more than one connection at a time (I'm judging by
nc -k
).
If so, just put tee
between your listening nc
and your wmbusmeters
:
nc -lk 1234 | tee -a /out_socat.txt | wmbusmeters …
Add nohup
(mind this) and/or &
at your discretion.