A while ago I made a script and I added some logging around it, but I forgot how the redirection for the logging works :-(
The gist of it is:
#!/bin/bash
LOGFILE=/some/path/mylogfile
(
# here go my commands which produce some stdout
# and, if something goes wrong, also some stderr
) 1>>${LOGFILE} 2> >( tee -a ${LOGFILE} >&2 )
When I run the script, it doesn't print anything to stdout
, but only prints what goes to stderr
. Logfile ${LOGFILE}
captures both stdout and stderr.
When I run the script and there is no output on my terminal, then I know everything is fine. If there is any output, I know something went wrong and I can check the logfile to find out what the problem is.
The part of the redirection that now puzzles me is the syntax of: 2> >( some command )
Can anyone explain what is going on there?