Does mysqldump return a status?
I am creating a script that backups a mysql db using the mysqldump utility. I am writing this script in the shell "sh". I would like to capture the output status of mysqldump in the script (i.e. if the mysqldump command failed or succeeded) s开发者_如何学编程o I can report if the script was successful or not.
Does mysqldump return an output status?
Can someone please give me instructions on how to do this?
although there seems to be no particular documentation about it, mysqldump yields an exit code of 0 on success and != 0 on error, as is conventional for console applications.
You'd use it like e.g.:
mysqldump -q -h host -u user database >db_dump.sql
EXITCODE=$?
if [ $EXITCODE -ne 0 ] ; then
echo "mysqldump failed with exit code $EXITCODE"
else
echo "mysqldump finished ok"
fi
精彩评论