I need to run a command in a terminal to continuously receive incoming messages from elsewhere on the network. I have no control over the formulation of the length of the message. The command, however, is able to receive and print one full message at a time (and I also have no control over this command).
My task is to forward this stream of messages to a local port. An app listening to that port will further process the messages. Here is the problem: I have to set a receiving buffer at the app (say 1024 bytes) and as TCP protocol follows (as heavily discussed here), the messages just go through not in its their original chunk
. And the length of the message may not be constant (as my example below)
I want to append one special character at the beginning and the end of the message that the command spits out in order to process them on the other side. Here is a more specific eg.:
On terminal, I run this command;
mycommand | tee | netcat localhost 2003
This command receives the messages in their original chunks and forwards to port 2003:
action_1_timestamp_2021_6_09_10_34_23_abort
action_2_timestamp_2021_6_09_10_34_34_success
...
action_193848_timestamp_2021_6_23_10_34_23_hold
How can I wrap each line above like this :
<action_1_timestamp_2021_6_09_10_34_23_abort>
before it is forwarded by netcat localhost 2003
. I am not very familiar with bash scripting.