sqlplus 'whenever' and standard error
794093Aug 31 2010 — edited Aug 31 2010I want to capture any SQLPlus errors from my script, and treat them separately from
when I get "normal" output.
It appears to me that SQLPlus is returning SQL errors to standard output, not standard
error. Is this correct? I tried using "2>~/tmp/rstats_output.txt" but did not get anything.
Here is what I am using:
sqlplus -s ${FW_DB_USER}/${FW_DB_PASSWD}@${FW_DB_SID} >~/tmp/rstats_output.txt <<EOF
whenever sqlerror exit sql.sqlcode
set heading off
SELECT COUNT(cust_num)FROM BL_DATA WHERE(disconnect_date IS NULL OR disconnect_date >= SYSDATE);
EOF
if [ "$?" != "0" ]
then
echo "Statistics report failed"
echo "SQLPlus error returned $?"
cat ~/tmp/rstats_output.txt | /bin/mailx -s "Statistics Report FAILED for `date +%D`" myemail@mydomain.com
fi