User Tools

Site Tools


software:shelllogfile

Shell Logfile

Something that makes product support really difficult is if the interesting output from the customer's script run doesn't end up in the logfile (or the logfile says something different from what the customer saw). Especially if the customer already closed the window and can only tell you what he saw from the back of his head. Fortunately, there's a very easy way to make sure you catch all of your script's output.

#!/usr/bin/env bash

exec >  >(tee -a foo.log)
exec 2> >(tee -a foo.log >&2)

As easy as that. All output to either stdout and stderr will also end up in logfile.txt. No more » $logfile.txt, no more | tee -a $logfile.txt, no more (forgotten) 2>&1 and all that stuff. If your script fails, you'll see exactly what the customer saw.

software/shelllogfile.txt · Last modified: 2018/09/10 16:21 (external edit)