Bash Linux -测试mysql命令是否成功执行

时间:2022-10-13 01:02:59

i wrote a script that make a dump of mysql dbs, i need to check if the command succfully executed or not. using $? give me always 0 even if there are a connection problem with the db server. any idea how can i do this thanks

我编写了一个转储mysql dbs的脚本,我需要检查命令是否成功执行。用美元吗?即使db服务器有连接问题,也要始终为0。你知道我该怎么做,谢谢。

1 个解决方案

#1


4  

Script

脚本

#!/bin/sh
mysqldump -h 192.168.1.10 -u user -pPaSSwOrD dbname > filename.sql
if [ "$?" -eq 0 ]; then
    echo "Success"
else
    echo "Error"
fi

is successfully showing errors for connection timeouts, wrong dbname, wrong username and password. It only doesn't check integrity of dump taken, but it's another story.

成功地显示了连接超时、错误的dbname、错误的用户名和密码的错误。它只检查不了转储的完整性,但这是另一回事。

#1


4  

Script

脚本

#!/bin/sh
mysqldump -h 192.168.1.10 -u user -pPaSSwOrD dbname > filename.sql
if [ "$?" -eq 0 ]; then
    echo "Success"
else
    echo "Error"
fi

is successfully showing errors for connection timeouts, wrong dbname, wrong username and password. It only doesn't check integrity of dump taken, but it's another story.

成功地显示了连接超时、错误的dbname、错误的用户名和密码的错误。它只检查不了转储的完整性,但这是另一回事。