Reputation: 33
I am working on a shell script and I have to execute a MySQL query from one server to a remote DB Server. I have written this script. Script was working fine until I added
where socialr_host = "http://$NEW/"
I think this is an issue of "" inside ''. Please help me with this, I don't have much knowledge to shell scripting
SERVER_USER="root"
SERVER_HOST="192.168.0.13"
MYSQL_HOST="localhost"
MYSQL_PASS="pass"
MYSQL_USER="root"
CORES_DATABASE="/root/Desktop/cores.db"
CORES_FILESYSTEM="/root/Desktop/cores.disk"
DIFF_FILE="/root/Desktop/diff.txt"
CORES_PATH="/raid/solr/cores"
NEW="db6055.da2"
ssh $SERVER_USER@$SERVER_HOST " mysql -u $MYSQL_USER -p$MYSQL_PASS -e 'select coloumn_name from table_name where socialr_host = "http://$NEW/";' database" > $CORES_DATABASE
Upvotes: 0
Views: 51
Reputation: 58788
You need to escape double quotes within double quotes:
ssh $SERVER_USER@$SERVER_HOST " mysql -u $MYSQL_USER -p$MYSQL_PASS -e 'select coloumn_name from table_name where socialr_host = \"http://$NEW/\";' database" > $CORES_DATABASE
However, there are several other issues with your code, and I would avoid using Bash for something as complicated as this. If you insist on using Bash, please read up on at least quoting and SSH quoting.
Upvotes: 2