[Solved] How can I execute an MySQL command through a shell script using if -else for condition based?


Mysql won’t understand if ..else shell syntax and so you will need to execute mysql within each if, else block with -e for execution e.g:

...
elseif [ "$(date +%m)" -eq 2 ]
then
 mysql --login-path=local -e "use testdb;select COUNT(id) from xxx where app_id ='ABC' and date(creation_date) between '$(date +%F -d  "tomorrow -28 days")' and '$(date +%F)' and action='AUTH' ;" >> /home/test.sql
else
...

3

solved How can I execute an MySQL command through a shell script using if -else for condition based?