Normally I can run a command to run a sql script via the commandline in the following manner in my server:
[ec2-user@ip-XX-XX-XX-XXX ~]$ sudo mysql -h BLAHBLAHBLAH.us-east-1.rds.amazonaws.com -u user -p'aaaaa:b>c[d{e]ff=|ggggggggg^$*' adi_chf_db < ./test.sql
So I wanted to make this simple and have a bash script run it for me:
#!/bin/bash
sql_cmd_to_run="sudo mysql -h BLAHBLAHBLAH.us-east-1.rds.amazonaws.com -u user -p\'aaaaa:b>c[d{e]ff=|ggggggggg^$*\' test_database < ./test.sql"
ssh -t test_server "${sql_cmd_to_run}"
My result is the following:
bash: ggggggggg^': command not found
ERROR 1045 (28000): Access denied for user 'user'@'XX.XX.XX.XXX' (using password: YES)
Connection to XX.XX.XX.XXX closed.
I also understand that there are some special characters in bash so I tried the following as well (by putting \ before the special characters):
#!/bin/bash
sql_cmd_to_run="sudo mysql -h BLAHBLAHBLAH.us-east-1.rds.amazonaws.com -u user -p\'aaaaa:b\>c\[d\{e\]ff=\|ggggggggg\^$\*\' test_database < ./test.sql"
ssh -t test_server "${sql_cmd_to_run}"
Which the output is:
ERROR 1045 (28000): Access denied for user 'user'@'XX.XX.XX.XXX' (using password: YES)
Connection to XX.XX.XX.XXX closed.
(I've obscured some of the values, obviously for some security reasons.)