I would like to run several commands, and capture all output to a logfile. I also want to print any errors to the screen (or optionally mail the output to someone).
add this at the beginning of your script
#!/bin/bash set -e outfile=logfile exec > >(cat >> $outfile) exec 2> >(tee -a $outfile >&2) # write your code here
STDOUT and STDERR will be written to $outfile, only STDERR will be seen on the console
STDOUT
STDERR
$outfile