<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"><<a href="mailto:athompso@athompso.net" target="_blank">athompso@athompso.net</a>></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 <<a href="mailto:kevin.a.mcgregor@gmail.com">kevin.a.mcgregor@gmail.com</a>> wrote:<br>
><br>
> The writer is:<br>
> #/bin/ksh<br>
> PIPE=/tmp/backup.pipe<br>
> [[ ! -a $PIPE ]] && mkfifo $PIPE<br>
> # Start gzip processes<br>
> /opt/cronjobs/zip1 &<br>
> /opt/cronjobs/zip2 &<br>
><br>
> # Process files needing compression<br>
> let 'fc=0'<br>
> ls /zonebackup/*tar | while read F; do<br>
> echo $F >$PIPE<br>
> let 'fc=fc+1'<br>
> done<br>
><br>
> echo "end of list" >$PIPE<br>
> echo "end of list" >$PIPE<br>
> exit 0<br>
><br>
> The readers are:<br>
> #/bin/ksh<br>
> PIPE=/tmp/backup.pipe<br>
> NAME=zip1<br>
> if [[ ! -a $PIPE ]]; then<br>
> logger -p local0.warning "$NAME can't find $PIPE -- exiting"<br>
> exit 1<br>
> fi<br>
><br>
> while (( 1 )); do<br>
> read F <$PIPE<br>
> if [[ "$F" = "end of list" ]]; then<br>
> break<br>
> else<br>
> echo "$NAME: $F"<br>
> fi<br>
> done<br>
><br>
><br>
><br>
> On Sat, Mar 1, 2014 at 1:29 PM, Kevin McGregor <<a href="mailto:kevin.a.mcgregor@gmail.com">kevin.a.mcgregor@gmail.com</a>> wrote:<br>
>><br>
>> I tried fiddling with IFS to no avail. I just changed it like this:<br>
>> IFS='<br>
>> '<br>
>> 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. <br>
>><br>
>><br>
>> On Sat, Mar 1, 2014 at 12:47 PM, Robert Keizer <<a href="mailto:robert@keizer.ca">robert@keizer.ca</a>> wrote:<br>
>>><br>
>>> Have you tried setting IFS ( field sep )? Also you could enable raw mode with -r.<br>
>>><br>
>>> Can you share the script?<br>
>>><br>
>>> Are the same lines failing repeatedly?<br>
>>><br>
>>> Rob<br>
>>><br>
>>> On 2014-03-01 11:55 AM, "Kevin McGregor" <<a href="mailto:kevin.a.mcgregor@gmail.com">kevin.a.mcgregor@gmail.com</a>> wrote:<br>
>>>><br>
>>>> 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>
>>>><br>
>>>> 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>
>>>><br>
>>>> Kevin<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>
>>>><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>
>>><br>
>><br>
><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>