procmail
[Top] [All Lists]

cat foo | bar > foo (RE: Round Robin for email using Procmail)

2000-06-29 22:46:14
On Wed, 28 Jun 2000, Dallman Ross wrote:

After I said on the list yesterday that

      cat rrobinlist | sed > 's/^\([^,]*\),\(.*\)/\2,\1/' > rrobinlist

There looks to be an extraneous ">" in that sed command ...

would not work (would null out the file after the redirect to the file),
I had private mail with the original author, Lee Howard, who showed
me that it does work for him.  I investigated, and found out that
he's right - as long as the environment setting for noclobber is
not turned on.

He's only right as long as the size of the file is less than the size of
the operating system buffer in the pipeline between cat and sed (plus
the size of the stdio or similar buffers used by cat and sed, if any).
That is, it works only if "cat" can read the entire file and pipe it
through to sed before sed begins to produce any output.

It's also highly dependent on the shell's implementation of pipelines.
As it's the shell that opens the file for output before starting sed,
it could easily decide to do so before starting cat as well.

As none of this should be relied upon, your original objection was
correct.  The only correct way to do the above for an arbitrarily large
file is somthing like

        sed 's/^\([^,]*\),\(.*\)/\2,\1/' < rrobinlist > rrtmp &&
        mv -f rrtmp rrobinlist

Which of course has a race condition unless you use it in a locking
recipe.



_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>