[wplug] Line-by-line input from stdin, from a bash script ?

Drew from Zhrodague drewzhrodague at zhrodague.net
Mon Oct 14 13:49:32 EDT 2013


On 10/14/13 1:09 PM, Pat Barron wrote:
> On 10/14/2013 12:56 PM, G.Pitman wrote:
>> Not sure I understand your goal entirely but would a fifo work?
>
> Kind of a long story...  But in short, when the script is invoked, it's
> stdin is going to be attached to a socket, and the script is fired off
> from xinetd.  (And, of course, stdout is a network connection too...)
>
> What I want to do is basically:
>
> 1)  Read line from stdin (which is really a network connection)
> 2)  Do something with it
> 3)  Repeat as necessary...
>
> Of course, what I "do with it" in step 2 (and what happens next...)
> depends on what is previously read.  I have found (by experimentation)
> that I can't just read stdin until end of file and then process
> everything in one go, because the other side doesn't actually close the
> connection until it's told do so, so that just hangs forever, waiting
> for further instructions....)
>
> I'll tell you exactly what I'm doing, so you can all laugh at me...
> (This is strictly a hobby project at the moment, it doesn't have to make
> sense...)  I'm trying to implement a (reasonably complete) web server in
> shell scripts....

cat <socket> | awk -F\n '{print "command " $1 " more command"}' | sh

	This will require that there's a ctrl-D at the end, so it would run the 
commands. You may need one process to cat > file, and a separate process 
(cron?) to pick the last line of the file, and do something with it.

	YOu could have an xinetd script that reads each connection, writes it 
to a file, and calls a second process on that. Many of us can help you 
with some bash-fu.

	note: bash is freaking horrible as a programming language - but it 
works. I write almost everything in bash.


-- 

Drew from Zhrodague
secret intelligence and mind control
drew at zhrodague.net


More information about the wplug mailing list