From 77f29da0ac0d79fefa3f4f155a7f523ae3da6f7f Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 31 Jan 2019 04:03:35 +0100 Subject: [PATCH] repair_mysql_tables.sh: fix errors for support of multiple installations. --- repair_mysql_tables.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/repair_mysql_tables.sh b/repair_mysql_tables.sh index 144c542..9953e3a 100755 --- a/repair_mysql_tables.sh +++ b/repair_mysql_tables.sh @@ -182,8 +182,9 @@ fi # ------------- if [[ -n "$1" ]] ; then - DATABASES="$1" + GIVEN_DATABASE="$1" else + GIVEN_DATABASE="" if $terminal ; then warn "No Databses given!" @@ -252,16 +253,27 @@ for _val in ${mysql_credential_args_arr[@]} ; do mysql_version="${_val_arr[0]}" mysql_credential_args="${_val_arr[1]}" + DATABASES="$($mysql $mysql_credential_args -N -s -e "show databases")" - if [[ -z "$DATABASES" ]] ; then + if [[ -z "$GIVEN_DATABASE" ]] ; then if $terminal ; then echo "" echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: repair (and optimize) tables of databases at host '$(hostname -f)'." fi - DATABASES="$($mysql $mysql_credential_args -N -s -e "show databases")" ALL_DATABASES=true + else + found=false + for db in $DATABASES ; do + if [[ "$db" = "$GIVEN_DATABASE" ]]; then + DATABASES="$GIVEN_DATABASE" + found=true + fi + done + if ! $found ; then + continue + fi fi length_table_name=0 @@ -273,7 +285,11 @@ for _val in ${mysql_credential_args_arr[@]} ; do if $terminal ;then echo "" - echo -e " [$(date)] Repair (and optimize) tables in database '${db}'.." + if [[ -n "$GIVEN_DATABASE" ]] ; then + echo -e " [$(date)] Repair (and optimize) tables in database '${db}'.." + else + echo -e " [ \033[37m\033[1mMySQL $mysql_version\033[m $(date) ] Repair (and optimize) tables in database '${db}'.." + fi fi TABLES="$($mysql $mysql_credential_args $db -N -s -e "show tables" 2> $tmp_log_file )"