Discussion:
[Help-bash] BASH_XTRACEFD on stdout
Matthew Lenz
2018-03-15 13:59:51 UTC
Permalink
I wasn't thinking and thought:

BASH_XTRACEFD=1
set -x
commands

wouldn't bite me, but of course it did (piping between commands)

I switched out to the following:

exec 4>&1
BASH_XTRACEFD=4
commands

The reason I'm doing this is because I have a cronjob that I'd like to do
the following:

script.sh 2>&1 >> logfile | tee -a logfile

This puts the stdout, debugging and stderr in my logfile but also allows
stderr to flow through in a mail notification.

It appears to not cause problems. Any reason to think otherwise?
Greg Wooledge
2018-03-15 14:52:46 UTC
Permalink
Post by Matthew Lenz
exec 4>&1
BASH_XTRACEFD=4
commands
The reason I'm doing this is because I have a cronjob that I'd like to do
script.sh 2>&1 >> logfile | tee -a logfile
This puts the stdout, debugging and stderr in my logfile but also allows
stderr to flow through in a mail notification.
It appears to not cause problems. Any reason to think otherwise?
There may be some desynchronization of stdout's lines in the log since
they're being written by the tee process instead of by the script.
As far as I know, that's unavoidable, due to the complexity of your
desired setup.

If this is working as you desire (or close enough), then it seems OK.
Matthew Lenz
2018-03-15 15:23:49 UTC
Permalink
Post by Greg Wooledge
Post by Matthew Lenz
exec 4>&1
BASH_XTRACEFD=4
commands
The reason I'm doing this is because I have a cronjob that I'd like to do
script.sh 2>&1 >> logfile | tee -a logfile
This puts the stdout, debugging and stderr in my logfile but also allows
stderr to flow through in a mail notification.
It appears to not cause problems. Any reason to think otherwise?
There may be some desynchronization of stdout's lines in the log since
they're being written by the tee process instead of by the script.
As far as I know, that's unavoidable, due to the complexity of your
desired setup.
If this is working as you desire (or close enough), then it seems OK.
Thanks. My main concern was impacting the "communication" (piping) between
processes like I saw with setting it equal to 1 like I had originally.
Loading...