I have a system that processes incoming emails to send them to the Blackbox app at my work. A high level script is maintained by inittab to always run and run a child script to do the actual work with this command:
$SCRIPT | nc -l -p $PORT
The script itself reads from the named pipe, performs a bit of parsing and processing the data before the call echo, to shuffle the data back through netcat to the process connected to $ PORT.
I need some method of processing incoming data from the far end of my channel. When I make a request in the application to close the connection, it sends back the string (I can determine it whatever I want) and waits for my script to close the channel. I'm currently trying to figure out how to add functionality to read input from the other end; make sure this is the command to close the pipe and then exit the script.
My script (in a nutshell) is as follows:
while true ; do
email_input="`cat "$pipe"`"
if [[ $email_input =~ .*escape_queue.* ]] ; then
break;
fi
echo "`parse`"
done
I am open to the possibility of changing the program flow, I just can’t turn my head around how I could read data coming asynchronously from script blocks on cat $pipe, until a new letter is received for processing.
If this is not clear, I am at an elementary level with bash scripts and always open to suggestions for improvement.
UPDATE
script
$SCRIPT | nc -l -p $PORT > $nc_data
script
netcat_response="`cat "$nc_data"`";
if [[ "$netcat_response" =~ "exit" ]] ; then
cat /dev/null > $nc_data
break;
fi
script , fifo. , 1 , script, script . script - cat, - . .