I know how to redirect stdout & stderr to one file:
my_command_to_start_server &> app.log
but how can I redirect the stdout & stderror to 2 files?
In essence I want to duplicate what's getting written to my app.log to my health.log
I know how to redirect stdout & stderr to one file:
my_command_to_start_server &> app.log
but how can I redirect the stdout & stderror to 2 files?
In essence I want to duplicate what's getting written to my app.log to my health.log
Use tee
.
my_command_to_start_server 2>&1 | tee app.log health.log > /dev/null
2>&1
makes standard error whatever standard output already is, effectively "merging" them. (&> ...
is a shortcut for > ... 2> ...
, which doesn't allow for the use of a pipe.) Then you pipe the merged stream to tee
, which writes its standard input to both named files.
tee
also writes to its own standard output, which we redirect to /dev/null
instead of picking an arbitrary file to redirect standard output to with something like
... | tee health.log > app.log