How do I get the exit code while directing the command output to a file?
by cesarsj from LinuxQuestions.org on (#4W3KD)
I am canceling the mysql command on purpose to have error exit code. In the command below, the exit code is being 0 successful because of the tee. How can I solve this?
Code:mysql --defaults-extra-file=/etc/my.cnf.d/.mylogin.cnf -e"use radius; call sp_monthly_table_backup(@Msg);" | tee -a $CLEARLOG $ZBXLOG > /dev/null;
EXITCODE=$(echo $?);


Code:mysql --defaults-extra-file=/etc/my.cnf.d/.mylogin.cnf -e"use radius; call sp_monthly_table_backup(@Msg);" | tee -a $CLEARLOG $ZBXLOG > /dev/null;
EXITCODE=$(echo $?);