From e843575d947c3b427a0d18ae960a5337ff361aa8 Mon Sep 17 00:00:00 2001 From: paspo Date: Sun, 15 Jun 2025 17:47:09 +0200 Subject: [PATCH] script shellchecked --- healthcheck.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/healthcheck.sh b/healthcheck.sh index 7de28be..fa327c0 100755 --- a/healthcheck.sh +++ b/healthcheck.sh @@ -1,14 +1,19 @@ #!/bin/bash +MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-nopassword} + # slave not configured -RES=$(mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e 'SHOW SLAVE STATUS\G') -if [ "a$RES" = "a" ]; then +SLAVE_STATUS=$(mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" -e 'SHOW SLAVE STATUS\G') +if [[ -z "${SLAVE_STATUS}" ]]; then exit 0 fi +# extract slave status +SLAVE_IO=$(echo "${SLAVE_STATUS}" | awk -F: '/Slave_IO_Running/ {gsub(/ /, "", $2); print $2}') +SLAVE_SQL=$(echo "${SLAVE_STATUS}" | awk -F: '/Slave_SQL_Running/ {gsub(/ /, "", $2); print $2}') + # slave ok -RES=$(mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ',') -if [ "$RES" = " Yes, Yes," ]; then +if [[ "${SLAVE_IO}" == "Yes" && "${SLAVE_SQL}" == "Yes" ]]; then exit 0 fi