olafz / percona-clustercheck

Script to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluster nodes properly. The clustercheck script is distributed under the BSD license.
BSD 3-Clause "New" or "Revised" License
173 stars 108 forks source link

Update clustercheck #23

Open Newbeeee opened 5 years ago

Newbeeee commented 5 years ago

syntax error

Cougar commented 5 years ago

The problem is only with MYSQL_USERNAME but your fix is wrong here. Your change won't keep empty variable and therefore it is not possible to put username and password in /etc/my.cnf. I didn't find it in bash manual but this is how the MYSQL_PASSWORD works ('!' is not allowed in command line):

>echo "${MYSQL_PASSWORD-clustercheckpassword}"
clustercheckpassword
>export MYSQL_PASSWORD=''; echo "${MYSQL_PASSWORD-clustercheckpassword}"

>export MYSQL_PASSWORD='x'; echo "${MYSQL_PASSWORD-clustercheckpassword}"
x

but

>export MYSQL_PASSWORD=''; echo "${MYSQL_PASSWORD:-clustercheckpassword}"
clustercheckpassword

In second case the https://github.com/olafz/percona-clustercheck/blob/d5da8bed4ead8440dbef33c8959be42e37e881ae/clustercheck#L52-L54 condition doesn't add --password parameter which is intentional. Otherwise it always overrides password in /etc/my.cnf.

The same should be with MYSQL_USERNAME.

With :- syntax it is not possible to have empty variable and https://github.com/olafz/percona-clustercheck/blob/d5da8bed4ead8440dbef33c8959be42e37e881ae/clustercheck#L49-L54 is pointless.