Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash Linux - Test if mysql command succsfully executed

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

like image 442
Khaled_Jamel Avatar asked Mar 09 '26 23:03

Khaled_Jamel


1 Answers

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.

like image 138
Shader Avatar answered Mar 12 '26 12:03

Shader



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!