So i want socat to persistently listen for connections, get the first x lines and reply back with a message. Ideally i want to use a user defined function to handle that logic but i couldn't find a way to achieve that.
My scenario:
client 1:
cat <(printf "line1\nline2\n") -|nc socat_server socat_port
client 2:
cat <(printf "line3\nline4\n") -|nc socat_server socat_port
I want to get: line1 and line3 and the clients a message (e.g. EXIT)
I've tried with:
exec {fd}> >(my_custom_function)
socat tcp-listen:10000,reuseaddr,fork system:"head -n1>&$fd;echo EXIT;exit"
but i get "Bad fd number". Any ways around this?
head