sortie mysql en html table-script script

J’exécute une requête mysql renvoyant deux colonnes dans un script shell

TABLES=$($MYSQL -u $MUSER -p$MPASS -h $MHOST $MDB -e "SELECT table_name, ROUND(((data_length + index_length) / 1024 / 1024 / 1024), 2) AS table_size FROM information_schema.tables WHERE table_schema = 'inventory' AND CREATE_TIME < DATE(NOW()) -INTERVAL 7 DAY" | awk '{ print $1}' | grep -v '^table_name' ) 

Comment puis-je le stocker dans un tableau 2D et afficher le résultat sous forme de tableau HTML?

En guise de travail, j’exécute deux requêtes mysql et stocke le résultat dans deux tableaux distincts

  TABLES=$($MYSQL -u $MUSER -p$MPASS -h $MHOST $MDB -e "SELECT table_name FROM information_schema.tables WHERE table_schema = 'inventory' AND CREATE_TIME < DATE(NOW()) -INTERVAL 7 DAY" | awk '{ print $1}' | grep -v '^table_name' ) declare -a TABLE_SIZE=($($MYSQL -u $MUSER -p$MPASS -h $MHOST $MDB -e "SELECT ROUND(((data_length + index_length) / 1024 / 1024 / 1024), 2) AS table_size FROM information_schema.tables WHERE table_schema = 'inventory' AND CREATE_TIME < DATE(NOW()) -INTERVAL 7 DAY" | awk '{ print $1}' | grep -v '^table_size' )) #IF there are no tables in databse if [ "$TABLES" == "" ] then echo "Error - No table found in $MDB database!" exit 3 fi i=0 for t in $TABLES do #echo "Deleting $t table from $MDB database..." str=" $t ${TABLE_SIZE[$i]}" i=`expr $i + 1` table_array+=$str done table_array+="" 

Une option est de faire ceci par mysql avec l’option -H et l’option -N si vous ne voulez pas de noms de colonnes.

 mysql -H -N -u $MUSER -p $MPASS -h $MHOST $MDB < your_sql 

Si vous avez besoin d'une personnalisation HTML supplémentaire, vous pouvez faire quelque chose comme:

 #!/bin/bash # Set the internal file separator to newline. IFS=$'\n' echo "" # Loop over each row. for line in $(mysql -N ... < your.sql) do echo " " # Set the internal file separator to space/tab. IFS=$' \t' # Create columns array. columns=($line) echo " " echo " " echo " " done echo "
${columns[0]}${columns[1]}
"