run query in shell script after ssh

Hi,

I need to run sql query in shell script after getting connected to ssh. For that I connected to ssh through shell script using RSA keys [done]. Now when I am running sql query, it's not working... but several other commands like 'ls'. 'mkdir', etc are working properly.

Here is my code:

query="select status, count\(*\) from transact\;"
ssh user@ip <<FILE
# All commands working in this line
echo "hello"; ls; mkdir newfolder; echo $query
# sql command is not working
print $query | sql
exit
FILE
echo "DONE!!"

Also the same line " print $query | sql " works on command line after being connected to ssh.

I am getting these errors:
(1) stty: : Invalid argument
stty: : Invalid argument
stty: : Invalid argument
ksh[3]: sql: not found

please help.

Thanks.

print $query

??? maybe you want echo "$query"

Also seems sql is not in your PATH. you can just reference it by full-path .

echo "$query" | /usr/bin/sql

Its not working either.
echo and print, both works if used on command line