I have written a shell script which executing some of the mysql commands.
I want to run that shell script from rails side. And want to get result back of commands to rails from shell script.
How may i handle it?
EDIT:
script.sh
mysql -u root -pmysql << eof
SELECT TABLE_NAME AS "Table Name", table_rows AS "Quant of Rows", ROUND((data_length + index_length)/1024/1024,2) AS "Total Size Mb" FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema='database_name';
eof
This is my script. How may i return SELECT query result to rails ?
You can do something like this, it will block until the script is finished and any output that it sent to standard out will be contained in the
output
variable.Use backticks ` `
Edit
To get the output of a mysql statement, use the
-e
flagEg.
mysql -e "SELECT * from information_schema"