In attempting to verify if a remote database exists or not, I'm seeing mixed behavior with a conditional statement.
Technically the statement is working (it correctly reports if database is found), but on fail (no database found), it's throwing an error that I'm unable to trace for some reason.
REMOTE_EXISTS=$(mysql --login-path=$REMOTE_HOST --batch --skip-column-names -e "SHOW DATABASES LIKE '"$REMOTE_DB"';" | grep "$REMOTE_DB") if [[ $? != 0 ]]; then die "Checking for $REMOTE_DB failed. Please report this error." elif [[ $REMOTE_EXISTS ]]; then vrb "The database '$REMOTE_DB' has been found to exist on '$REMOTE_HOST'. Proceeding." else die "Oops! We couldn't find '$REMOTE_DB' on the '$REMOTE_HOST' server. Are you sure it's there?" fi
Unsure where I'm going wrong. Login details are being passed via stored configurations from
mysql_config_editor, which leads me to believe it's something fundamentally wrong with how my condition or method of going about this is setup.
Unfortunately, the error is vague and being caught in a trap in my script, so reporting is a bit fuzzy. Also, I've tried the following as well:
[ "$REMOTE_EXISTS" -eq 0 ]
[[ "$REMOTE_EXISTS" ]]
No better luck.
Help is appreciated, thank you!