[lug] Process substitution.

David L. Anselmi anselmi at anselmi.us
Sun Sep 19 21:12:31 MDT 2010


Lee Woodworth wrote:
> On 09/19/10 10:41, David L. Anselmi wrote:
>> I've recently found some uses for bash's process substitution (didn't think I would but what do I
>> know?)  But it seems hard to tell whether it will work or not for different programs.  Does anyone
>> know why some don't work?
>>
>> For example, if I have programs a and b and I want to compare their output, these lines do the same
>> thing:
>>
>>     diff <(a) <(b)
>>     a >  a.txt ; b >  b.txt ; diff a.txt b.txt
>>
>> But logrotate doesn't work like diff.  It takes a config file as an argument but won't read this:
>>
>>     logrotate<(# code to generate config file here)
>
> Assuming you are using bash, the process substitution section says it is using fifos. So
> your diff example above is not exactly equivalent.

The behavior of diff is the same.  That's what I care about.

> Can your config generating command tolerate being connected to fifos (which have different
> blocking behavior than files)?

Yes.  I've used it (usually echo or cat) in other cases just fine.  It isn't a problem writing to 
the FIFO, it's a problem reading it.

I first ran into this with a proprietary app (piece of junk, I thought).  But now logrotate does it 
too so I'm wondering why.  I'm sure there's a guru out there who gets it.  Kind of like 
understanding why you can delete read only files.

On the RH4 version of logrotate the script below gives an error about not opening /dev/fd/63 
(permissions, or read error, or something).  In my current version (Debian 3.7.8-6) it silently 
succeeds in doing nothing.  If I run with -d it says:

   Ignoring /dev/fd/63 because it's not a regular file.

   Handling 0 logs

So the problem isn't with creating the config or writing it to the fifo.  It must be that it's 
open() doesn't like fifos.  vi doesn't either, but vi assumes it will have to seek in the file so it 
would be stupid to try to edit a fifo.  But logrotate only reads its config AFAIK.  So its prejudice 
seems silly.

Here's the script (run from the bash prompt):

   logrotate -d -s /home/dave/tmp/state <(echo "/home/dave/tmp/Logrotate/a.log {
   rotate 5
   daily
   size 1
   }")

Thanks!
Dave



More information about the LUG mailing list