Operating System - HP-UX
1820389 Members
3864 Online
109623 Solutions
New Discussion юеВ

ssh executing commands on a remote server.

 
SOLVED
Go to solution
Jacques Carriere
Regular Advisor

ssh executing commands on a remote server.

Can anyone qive me the correct syntax to execute sql on a remote serveur using ssh.

eg. ssh user@rserver "sql .."

If I append the sql statement at the end of the .profile of the user@rserver, the sql works. Any other way, the command doesn't work.

Jacques

6 REPLIES 6
Denver Osborn
Honored Contributor

Re: ssh executing commands on a remote server.

What error is returned when you run it using ssh user@rsever "sql ..."?

Do you get the same results if using the -n option with ssh?

ssh -n user@rserver "sql ..."


-denver

Ralph Grothe
Honored Contributor

Re: ssh executing commands on a remote server.

SQL over SSH isn't the best option I would say.
Better use something like the Perl DBI.
However, you could try something like this.
(note, providing SID's credentials like this is a very bad thing)

$ ssh ruser@sqlserver ORACLE_SID=BLA ORACLE_HOME=/path/to/oracle/installation echo 'select foo from v$bar;' \| /path/to/sqlplus -S username/passwd
Madness, thy name is system administration
OldSchool
Honored Contributor

Re: ssh executing commands on a remote server.

note that the ssh man page states:

If command is specified, it is executed on the remote host instead of a login shell.

that implies (but I haven't verified) that the profile hasn't run, and that their isn't a shell running to interpret commands.

put your sql in a script, make sure the environment is set the way you want and try running it with a full path to the script

Srikanth Arunachalam
Trusted Contributor

Re: ssh executing commands on a remote server.

Hi,

You may have a remote shell script that would actually run the SQL script. Use the following command to ssh

output=`ssh user@remote_box /home/tom/run_dbscript.sh 2>/dev/null`

Make sure that you have a SSH key defined in the remote server.

Inside run_dbscript.sh you need to have logic for connecting to database and executing the SQL procedure.

Thanks,
Srikanth
Srikanth Arunachalam
Trusted Contributor
Solution

Re: ssh executing commands on a remote server.

Hi,

You may have a remote shell script that would actually run the SQL script. Use the following command to ssh

output=`ssh user@remote_box /home/tom/run_dbscript.sh 2>/dev/null`

Make sure that you have a SSH key defined in the remote server.

Inside run_dbscript.sh you need to have logic for connecting to database and executing the SQL procedure.

sqlplus -s system/manager as sysdba << EOF
set echo on feed off veri off pages 0 head off
select database_role from V$DATABASE;
exit
EOF

Thanks,
Srikanth
Jacques Carriere
Regular Advisor

Re: ssh executing commands on a remote server.

problem solved