Try use some "proxy" to input. For example "cat":
if [[ ! -p "in" ]]; then mkfifo "in"; fi
(while true; do cat in; done) | (while true; do
nc -Ul sock >> "out"
done)
Domanda
I need to write a script - preferably a bash script - that will listen on a Unix domain socket and pipe the output to a log file while receiving input through a FIFO. The FIFO / log end is supposed to mimic the style of ii. The script also be able to monitor and react to the input from the FIFO (e.g. for a "stop" function).
This is as far as I got:
if [[ ! -p "in" ]]; then mkfifo "in"; fi
while true; do
nc -Ul sock >> "out"
done
I'm stuck on how to get the input from the FIFO into netcat
. When I add < "in"
and try to connect to the socket from another shell the connection is refused. Strangely enough, it works just fine when I replace "in" with a regular file.
What's the easiest / correct way to do this?
Edit: Using the pipes on the whole while
block has the same effect.
Soluzione
Try use some "proxy" to input. For example "cat":
if [[ ! -p "in" ]]; then mkfifo "in"; fi
(while true; do cat in; done) | (while true; do
nc -Ul sock >> "out"
done)