[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: HP-UX exec tee hanging/not working intermittently

From: Andrew Resch
Subject: Re: HP-UX exec tee hanging/not working intermittently
Date: Tue, 31 Jul 2012 10:09:55 -0700

On Tue, Jul 31, 2012 at 4:55 AM, Greg Wooledge <address@hidden> wrote:
> On Mon, Jul 30, 2012 at 02:17:15PM -0700, Andrew Resch wrote:
>>         I am attempting to use exec and tee to have my scripts
>> stdout/stderr appended to a log file like such: exec > >(tee -a $LOG)
>> 2>&1
>>         These scripts will often call other scripts with a similar
>> exec statement, often writing to a separate log file.  On my GNU/Linux
>> systems,
>>         these scripts will run just fine without any issue, but on
>> HP-UX they seem to hang or not display any output.
> The major difference here is that bash on HP-UX implements process
> substitutions (the <() syntax) with a named pipe, whereas on Linux
> it uses a /dev/fd/* file.
>> $ cat test_exec1.sh
>> #!/bin/bash
>> LOG="test_exec.log"
>> exec > >(/usr/bin/tee -a $LOG) 2>&1
>> echo "i am exec1.."
>> ./test_exec2.sh
>> echo "i am done in exec1.."
>> $ while true; do ./test_exec1.sh; done
> You are opening a slew of named pipes and background jobs in rapid
> succession, and not waiting for the jobs to finish.  (It might still be
> considered a bug... I'm just pointing out the practical aspects.)
> I would bet that putting a "sleep 1" in the loop would make the problem
> stop happening, as horrible a hack as that may be.

Yes, fair enough.  I did the loop to simply make the issue more apparent,
but many times I couldn't even run the test_exec1.sh script once successfully
on one of my hosts.  In those cases I'm not sure how large of a sleep
I'd need to make it work ;)

> I discuss this a bit on <http://mywiki.wooledge.org/BashFAQ/106>.  The
> only way to ensure clean operation is to avoid the <() syntax altogether
> and use your own explicit named pipe and background job.  Then you can
> close the pipe and wait for the background job to terminate before
> exiting.

Thank you for this.  I have removed the process substitution from my scripts
and replaced it with using explicit named pipes, and now everything is
working as expected.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]