I want to run a shell script for some group of mysql commands and the result of those commands should be saved in separate o/p file. The o/p file should contains both the query and its result.
!/bin/bash
(mysql -u root -p -e "use mysql; select version(),now(); select table_schema, sum(data_length+index_length)/1024/1024 as Total_in_mb, sum(data_length)/1024/1024 as Total_data_in_mb, sum(index_length)/1024/1024 as Index_in_mb, count(*) as tables from information_schema.tables group by table_schema; show global variables; show global status; show innodb status;") | tee -a /root/fgfgfg.sql
By using the above shell script i am only getting the results of the query but not the query it self. And one most important thing is i will run this script on last day of the month on hourly basis from 10Am - 5pm during this time can it possible to run the script and the o/P of the script should be saved in a septate file with different names.