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 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki