[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: |
Greg Wooledge |
Subject: |
Re: HP-UX exec tee hanging/not working intermittently |
Date: |
Tue, 31 Jul 2012 07:55:57 -0400 |
User-agent: |
Mutt/1.4.2.3i |
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.
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.