LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Processing Piped Data (https://www.linuxquestions.org/questions/linux-newbie-8/processing-piped-data-4175508716/)

NickLeMesurier 06-21-2014 08:57 AM

Processing Piped Data
 
Hi,

I've built a proxy using nc and some pipes. What I need to do is process the data coming through that proxy and perform certain actions if conditions are met. For example if a HTTP response code is 200 then run a script perhaps, the data must not be halted in transit. I'm very limited in what I can use, hence using nc for a proxy. Currently I'm piping out the data in transit and reading it from a background process, I'm struggling to capture the data correctly in the background process to be able to process it though.

proxy:

nc -l -p 9090 <pipe.back | tee pipe.process | nc 127.0.0.2 9999 >pipe.back

Ideally I would like foo.sh to be able to process the data and perform actions. Currently it looks like this, I've tried a number of things to store the data in a variable etc but nothing is working.

foo.sh:

tee <pipe.process

Any help is much appreciated :) Thanks, Nick

Shadow_7 06-21-2014 10:23 AM

I'm not sure if I understand your command. The -l is for listen, but you're piping TO it? Shouldn't the > / < be reversed? Your second nc probably needs a -n before the ip and port values. I use those often to send files between computers without having to setup an ftp server or network share. The down side is having to be near or at both computers or setup a timeout (-w) for that usage. And knowing the name of the filename to write it as on the destination machine. But it can be renamed later.

NickLeMesurier 06-21-2014 10:36 AM

The first named pipe is writing back into the nc listener. What the nc listener recieves is being output through the unamed piped and written to pipe.process. This output is also being piped further through another unamed pipe into the nc connection to 127.0.0.2. This connection is writing its responses into pipe.back which in turn are being read by the listener and passed back to the connecting client. I need to process what is being written into pipe.process. To simplify things, I could ask the question "How do I read from a named pipe, process it and execute a script upon a condiction being met?" as i need to process what is passing through the pipe.process named pipe.

shivaa 06-21-2014 01:04 PM

You are using process substitution in wrong way. Enclose command in braces whose output is to be substituted, as:
Code:

nc -l -p 9090 <(pipe.back) | tee pipe.process | nc 127.0.0.2 9999 > pipe.back
(Source: http://www.tldp.org/LDP/abs/html/process-sub.html)


All times are GMT -5. The time now is 04:29 PM.