A cron job runs a script that outputs to stdout. The administrator wants to capture both stdout and stderr to a file named job.log, while also seeing output on the terminal. Which command achieves this?
Redirects stderr to stdout and pipes to tee for file and terminal output.
Why this answer
Option D is correct because it uses `2>&1` to redirect stderr to stdout, then pipes the combined stream to `tee job.log`, which writes to the file and also displays output on the terminal. This ensures both stdout and stderr are captured in `job.log` and visible on the screen.
Exam trap
The trap here is that candidates often place `2>&1` after the pipe (as in option B), mistakenly thinking it redirects the script's stderr, when in fact it only affects the command receiving the pipe (e.g., `tee`), leaving the script's stderr uncaptured.
How to eliminate wrong answers
Option A is wrong because `script` is a command that records terminal sessions, not the script to be executed; it would try to run `script` with `2>&1` and pipe its output to `tee`, which does not execute the intended script. Option B is wrong because the `2>&1` appears after the pipe, so it redirects stderr of `tee` (not the script) to stdout, failing to capture the script's stderr in the file or terminal. Option C is wrong because `./script > job.log 2>&1` redirects both stdout and stderr to the file but does not display output on the terminal, violating the requirement to see output on the terminal.