2012-12-09 37 views
6

Ho un problema con la formattazione dell'output di MySQL mentre eseguo i comandi da uno script bash.MYSQL differisce in Output dallo script

Se eseguo un comando sulla riga di comando, sono in grado di ottenere l'output formattato come previsto.

$ mysql -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics" 
+---------------------+---------------------+ 
| now()    | max(time_stamp)  | 
+---------------------+---------------------+ 
| 2012-12-09 14:25:38 | 2012-12-09 14:25:20 | 
+---------------------+---------------------+ 

Ma dove, come se mantengo lo stesso comando in uno script ed eseguito, non ottengo l'output formattato.

$ cat test 
#!/bin/bash 
mysql -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics" 

$ ./test 
now() max(time_stamp) 
2012-12-09 14:27:52  2012-12-09 14:27:47 

Quindi tutto ho bisogno la stessa uscita dallo script.

Grazie.

risposta

12

Passa l'opzione -t o --table per forzare l'output della tabella.

mysql --table -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics" 

Da mysql --help:

-t, --table   Output in table format. 
+1

ringrazio molto, si sta lavorando e dando i risultati attesi. –

Problemi correlati