如何从 Ubuntu shell 运行 mysql 查询时检查错误?

如何从 Ubuntu shell 运行 mysql 查询时检查错误?

我正在运行一个 shell 脚本来为我做各种事情。我的想法是将其添加到 crontab。以下是示例命令show databases

EMAILID="[email protected]"

T="/tmp/cleanup.info"

echo "starting backup process at $Now " >> $T


MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"

mysqlport="3306"
mysqluser="someroot"
mysqlpass="pass"
mysqlhost="localhost"

echo "querying the database for record older than date $Lastweekdate " >> $T


DBS="$($MYSQL -u $mysqluser -h $mysqlhost -p$mysqlpass -Bse 'show databases');"

##if noerror then

## echo "success" >> $T
Subject="success"
##else
Subject="failure"
## echo "Backup failed" >> $T

##fi
## rm -f $T

/usr/bin/mail  -s $Subject "$EMAILID" <$T

正如您所见,我不知道如何检查操作是否成功。除此之外,一切都很顺利。

有人可以帮我阅读吗?

答案1

检查错误返回代码,它是$?

相关内容