I am trying to log messages to both console and a log file in a bash script. I am able to log the stdout message both in console and log file but not a stderr. Below is the script and output. Please help.
Script:
!/bin/bash
LOG_FILE='./test1.log'
exec 3>&1 1>>${LOG_FILE} 2>&1
echo "log to console and log file" | tee /dev/fd/3
echo "only to log file"
chmm 777 ${LOG_FILE}
Log file:
log to console and log file
only to log file
./log_to_console_and_file.sh: line 6: chmm: command not found
Console:
log to console and log file
I want the below error message to be shown in the console as well.
./log_to_console_and_file.sh: line 6: chmm: command not found
Thanks.