optimize_mysql_tables.sh: fix errors for support of multiple installations.

This commit is contained in:
Christoph 2019-01-31 03:44:24 +01:00
parent b61cc133f0
commit 170cb05242

View File

@ -211,9 +211,9 @@ fi
# -------------
if [[ -n "$1 " ]] ; then
DATABASES="$1"
GIVEN_DATABASE="$1"
else
DATABASES=""
GIVEN_DATABASE=""
fi
if $terminal ; then
@ -255,15 +255,34 @@ for _val in ${mysql_credential_args_arr[@]} ; do
mysql_version="${_val_arr[0]}"
mysql_credential_args="${_val_arr[1]}"
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: optimize (and repair) tables of databases at host '$(hostname -f)'."
fi
echo -e "[ MySQL $mysql_version ]: optimize (and repair) tables of databases at host '$(hostname -f)'." > $log_file
if [[ -z "$DATABASES" ]] ; then
DATABASES="$($mysql $mysql_credential_args -N -s -e "show databases")"
fi
DATABASES="$($mysql $mysql_credential_args -N -s -e "show databases")"
found=false
if [[ -n "$GIVEN_DATABASE" ]] ; then
for db in $DATABASES ; do
if [[ "$db" = "$GIVEN_DATABASE" ]]; then
DATABASES="$GIVEN_DATABASE"
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: optimize (and repair) tables of database '$GIVEN_DATABASE'."
fi
echo -e "[ MySQL $mysql_version ]: optimize (and repair) tables of database '$GIVEN_DATABASE'." > $log_file
found=true
fi
done
if ! $found ; then
continue
fi
else
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: optimize (and repair) tables of databases at host '$(hostname -f)'."
fi
echo -e "[ MySQL $mysql_version ]: optimize (and repair) tables of databases at host '$(hostname -f)'." > $log_file
fi
length_table_name=0
for db in $DATABASES ; do
@ -368,14 +387,25 @@ for _val in ${mysql_credential_args_arr[@]} ; do
info_messages_arr+=("MySQL $mysql_version: The optimization of the MySQL tables of all databases were successful.")
fi
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: Finished optimizing MySQL databases at host $(hostname -f)."
echo ""
if [[ -n "$GIVEN_DATABASE" ]] ; then
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: Finished optimizing MySQL database '$GIVEN_DATABASE'."
echo ""
fi
echo "" >> $log_file
echo "[ MySQL $mysql_version ]: Finished optimizing MySQL database '$GIVEN_DATABASE'." >> $log_file
echo "" >> $log_file
else
if $terminal ; then
echo ""
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: Finished optimizing MySQL databases at host $(hostname -f)."
echo ""
fi
echo "" >> $log_file
echo "[ MySQL $mysql_version ]: Finished optimizing MySQL databases at host $(hostname -f)." >> $log_file
echo "" >> $log_file
fi
echo "" >> $log_file
echo "[ MySQL $mysql_version ]: Finished optimizing MySQL databases at host $(hostname -f)." >> $log_file
echo "" >> $log_file
done
if [[ ${#info_messages_arr[@]} -gt 0 ]]; then