script shellchecked
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user