<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body >Yes. The paradigm is usually one reader. You can have many writers, and I do that all the time in my scripts, but only one reader. The proper paradigm is to change your scripts around so you have one reader that can then control or start your two previous readers.<div><br></div><div>You could also have an intermediate reader that then makes the decision which of two further fifos to write two, one for each of your other two previous readers. The best answer depends on what you're really trying to achieve with all this.&nbsp;</div><br><br>-------- Original message --------<br>From: Kevin McGregor <kevin.a.mcgregor@gmail.com> <br>Date:2014/03/01  16:48  (GMT-06:00) <br>To: Continuation of Round Table discussion <roundtable@muug.mb.ca> <br>Subject: Re: [RndTbl] Ksh scripting, named pipes <br><br><div dir="ltr">Aw. I was afraid of that. In my 'production' script there would be a long time between most reads, so it's unlikely there would be a problem, but I still don't want rare random failures. I'll find a work-around.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Mar 1, 2014 at 2:12 PM, Adam Thompson <span dir="ltr">&lt;<a href="mailto:athompso@athompso.net" target="_blank">athompso@athompso.net</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">Oh, it's obvious when I think about it - the behavior of a pipe with multiple readers is well-defined as being OS and clib-dependent.<br>

Each byte is only available to one reader, ever - if the reading is interleaved, each reader will get garbage.<br>
You can use tee(1) to write to multiple FIFOs at once, or just adapt the writing script to do so manually.<br>
-Adam<br>
<br>
On Mar 1, 2014 1:35 PM, Kevin McGregor &lt;<a href="mailto:kevin.a.mcgregor@gmail.com">kevin.a.mcgregor@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; The writer is:<br>
&gt; #/bin/ksh<br>
&gt; PIPE=/tmp/backup.pipe<br>
&gt; [[ ! -a $PIPE ]] &amp;&amp; mkfifo $PIPE<br>
&gt; # Start gzip processes<br>
&gt; /opt/cronjobs/zip1 &amp;<br>
&gt; /opt/cronjobs/zip2 &amp;<br>
&gt;<br>
&gt; # Process files needing compression<br>
&gt; let 'fc=0'<br>
&gt; ls /zonebackup/*tar | while read F; do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; echo $F &gt;$PIPE<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; let 'fc=fc+1'<br>
&gt; done<br>
&gt;<br>
&gt; echo "end of list" &gt;$PIPE<br>
&gt; echo "end of list" &gt;$PIPE<br>
&gt; exit 0<br>
&gt;<br>
&gt; The readers are:<br>
&gt; #/bin/ksh<br>
&gt; PIPE=/tmp/backup.pipe<br>
&gt; NAME=zip1<br>
&gt; if [[ ! -a $PIPE ]]; then<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; logger -p local0.warning "$NAME can't find $PIPE -- exiting"<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; exit 1<br>
&gt; fi<br>
&gt;<br>
&gt; while (( 1 )); do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; read F &lt;$PIPE<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; if [[ "$F" = "end of list" ]]; then<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; else<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "$NAME: $F"<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; fi<br>
&gt; done<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Sat, Mar 1, 2014 at 1:29 PM, Kevin McGregor &lt;<a href="mailto:kevin.a.mcgregor@gmail.com">kevin.a.mcgregor@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; I tried fiddling with IFS to no avail. I just changed it like this:<br>
&gt;&gt; IFS='<br>
&gt;&gt; '<br>
&gt;&gt; And now the readers show all kinds of gibberish! All lines have no whitespace, save for the newline at the end. I'm assuming it's at the end.&nbsp;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Sat, Mar 1, 2014 at 12:47 PM, Robert Keizer &lt;<a href="mailto:robert@keizer.ca">robert@keizer.ca</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Have you tried setting IFS ( field sep )? Also you could enable raw mode with -r.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Can you share the script?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Are the same lines failing repeatedly?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Rob<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On 2014-03-01 11:55 AM, "Kevin McGregor" &lt;<a href="mailto:kevin.a.mcgregor@gmail.com">kevin.a.mcgregor@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I have a main script which writes to a named pipe. Before it starts writing, it starts two other scripts which read from this pipe. The reading and writing is a list of file names, one per line. How do I ensure that each script reads one complete line from the pipe at a time (no more, no less)?<br>

&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I have a test set up, and it usually works, but sometimes a reader will get a blank line or just a "/" (but not any other part of a line)!<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Kevin<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt; Roundtable mailing list<br>
&gt;&gt;&gt;&gt; <a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
&gt;&gt;&gt;&gt; <a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; Roundtable mailing list<br>
&gt;&gt;&gt; <a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
&gt;&gt;&gt; <a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
<br>
_______________________________________________<br>
Roundtable mailing list<br>
<a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
<a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
</div></div></blockquote></div><br></div>
</body>