LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-21-2014, 09:57 AM   #1
NickLeMesurier
LQ Newbie
 
Registered: Jun 2014
Posts: 2

Rep: Reputation: Disabled
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
 
Old 06-21-2014, 11:23 AM   #2
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 2,501
Blog Entries: 1

Rep: Reputation: 488Reputation: 488Reputation: 488Reputation: 488Reputation: 488
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.
 
Old 06-21-2014, 11:36 AM   #3
NickLeMesurier
LQ Newbie
 
Registered: Jun 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
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.
 
Old 06-21-2014, 02:04 PM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem using piped data as input NirvanaII Programming 13 11-07-2010 08:03 AM
Pipelining data of find command in an array after processing the contents of the data AshishJogeshwar Linux - Software 5 06-10-2010 02:52 AM
Pipelining data of find command in an array after processing the contents of the data AshishJogeshwar Linux - Software 0 06-07-2010 07:15 AM
Processing data from a 'foreign' database with mysql, or tools to pre-process data. linker3000 Linux - Software 1 08-14-2007 09:36 PM
Data Processing joelhop Linux - General 8 01-01-2006 09:08 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration