1

I am trying to run a timesten sql query on a remote server from my local machine. The query is inside a script, I am able to connect to the db but the problem is with the query field.

This is my script runttquery.sh

#!/bin/bash
cmd=$1
ssh dba@rhost << "EOF"
ttIsql "dsn=rhostdsn";
select * from table1 where id='$cmd';
EOF

When I run the above script by passing an argument "testid", ./runttquery.sh testid

the $cmd in the sql query isn't getting replaced with the "testid" argument that I passed and I get 0 results from the remote server.

I just need to replace the id value in my sql query with the argument that I passed to the script.

  • You have to escape the single quoutes around $cmd, else it is interpreted as literal "$cmd" and not a variable. – guillermo chamorro Oct 22 at 21:37
  • @guillermochamorro Thanks! for the response, I tried the script again, this time I escaped the single quotes but still got the same result. – Dev Bin Oct 23 at 0:50
  • Is there a way to replace the variable with whatever value was passed to the script in the sql query? – Dev Bin Oct 24 at 21:12
0

I was incorrectly substituting the variable $cmd, I removed the quotes around EOF(heredoc limitstring) and add {} around $cmd. The following works perfectly fine now.

#!/bin/bash
cmd=$1
ssh dba@rhost << EOF
ttIsql "dsn=rhostdsn";
select * from table1 where id='${cmd}';
EOF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.