I'm looking for a solution (similar to the bash code below) to copy both stdout and stderr to a file in addition to the screen within ksh on Solaris.
The following code works great in the bash shell:
#!/usr/bin/bash
# Clear the logfile
>logfile.txt
# Redirect all script output to a logfile as well as their normal locations
exec > >(tee -a logfile.txt)
exec 2> >(tee -a logfile.txt >&2)
date
ls -l /non-existent/path
For some reason this is throwing a syntax error on Solaris. I assume it's because I can't do process substitution, and I've seen some posts suggesting the use of mkfifo
, but I've yet to come up with a working solution.
Does anyone know of a way that all output can be redirected to a file in addition to the default locations?
How about this:
Add
-a
to thetee
command line for subsequent invocations to append rather than overwrite.Which version of ksh are you using? The
>()
is not supported in ksh88, but is supported in ksh93 - the bash code should work unchanged (aside from the#!
line) on ksh93.If you are stuck with ksh88 (poor thing!) then you can emulate the bash/ksh93 behaviour using a named pipe:
The above is a second version to enable stderr to be redirected to a different file.
In ksh, the following works very well for me