Run sql query after ssh in UNIX

I am running this test.ksh on server1. It successfully logins to server2 but runs the queries of query.sql on server1. query.sql is present in both server1 and server2

Can anybody please help.
I need to run queries on server2 itself.:confused:
Below is the test script

server1:oracle1:/home/oracle1>./test.ksh server2
ssh oracle1@$1 
. oraenv
 $ORACLE_HOME/bin/sqlplus -s / @/home/oracle1/shruthi/query.sql

Maybe if you explained what you are up to can we help...
Because you have 2 options:
1) You connect using ssh balhblah -c YOURSCRIPT
2) You use a heredoc
(If you dont know what it is: Here Documents )

What you submitted will connect by opening a new shell on server2, the rest will continue to be executed by the script current shell...

1 Like

I am using ssh to remotely connect to a server.
All I need is to run the sql query on the remote server to which I have logged in using ssh. :o

---------- Post updated at 10:07 PM ---------- Previous update was at 10:04 PM ----------

I am using ssh to remotely connect to a server.
All I need is to run the sql query on the remote server to which I have logged in using ssh. :o

And where do you think the output will be?

What is preventing you from doing so? What have you tried?

As of now , I just need the output to be displayed on the terminal. As soon as the ssh command is interpreted, the host changes back to the local server.
I tried including

. oraenv  $ORACLE_HOME/bin/sqlplus -s / @/home/oracle1/shruthi/query.sql

...this part of the code inside single quotes...But it shows "oraenv: not found." message.

My question is all unix commands work fine if they are inserted within quotes, why not the above code??

It won't work if it's not a valid command. Try . oraenv ; command

To drop to a shell instead of quitting, try ssh -t ... 'command ; exec bash'

The -t forces it to allocate a terminal so interacting remains possible, and the 'exec bash' drops you to a shell once sql is done instead of quitting.

This is what I got!

ksh[3]: oraenv:  not found.
Connection to <remote server> closed.

My problem is, I am unable to launch sqlplus on remote server!!

Well, if there isn't an oraenv file in the current directory on the remote server, it's not going to be able to source it. (Don't just copy the one you have, it's probably different on the other server.)

Find it on the remote server or ask its administrator to tell you where it is.

Well

. oraenv

works fine after I ssh to remote server.
Its not working only when I am using it inside a script which contains ssh..:frowning:

Hmmm. So it's not executing your login script. What shell do you get when you login?