I have a small test script here, it has error handling. I would like all STDERR and STDOUT to be displayed on the console (which they currently are) AND made into a log file.
#!/bin/bash
# error handling
function error_handler() {
echo "Error occurred in script at line: ${1}."
echo "Line exited with status: ${2}"
}
trap 'error_handler ${LINENO} $?' ERR
set -o errexit
set -o errtrace
set -o nounset
if rsync -aPh ~/Downloads/Temps-linux-x64.zip .; then
echo "SUCCESSFULL rsync of files"
else
echo "FAILED rsync of files"
fi
I have tried to trap it by adding this to the start;
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>log.out 2>&1
but this (as it's supposed to) logs everything but has no output to the console. It's also causing the error handling to not work correctly so I need another solution.
echo
statements. – pfnuesel Nov 14 '16 at 14:28