1

I get below error but exit code shows zero . Is there a way to get exit code of db error. Because I will need to send email alert on basis of exit code or db error

mysqldump: Couldn't execute 'SHOW FIELDS FROM `v_comloc`': View 'crais.v_comloc' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them (1356)

My attempt

#!/bin/bash -x

mysqldump --opt --routines --single-transaction -p654321 -uroot -hlocalhost crais 2>>/var/log/failedJobs/mysqlCronJob.log |gzip -9 >/userBackupDrive/backupDatabases/crais.sql.gz

RESULT=$?
echo "Output code for $db is  : $RESULT "
if [ $RESULT -eq 0 ] ; then
    echo
  else
    echo "$DATE__  $db backup not successful" >> /var/log/failedJobs/dbError.log
fi
2
  • 1
    Looks like this error is not critical in MySQL terms which means it returns 0. You could probably assign the mysqldump output to a variable and go from there. Commented Aug 20, 2020 at 14:48
  • Oracle has the same approach: if you just ran 200 queries in a session, a boolean result does not provide enough information. The method in Oracle is to redirect all output to a log, and search for error codes, which were always like ABC-12345 starting in column 1 (e.g. SQL-02045 No such table or view.) mySql may have a similar convention. Commented Aug 20, 2020 at 15:05

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.