![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Execute db2 commands in unix | rollthecoin | AIX | 3 | 04-25-2008 10:17 PM |
| lom don't execute commands | pasalagua | SUN Solaris | 6 | 01-25-2008 01:22 PM |
| Can Xargs execute multiple commands of evry input file | nilesrex | Shell Programming and Scripting | 4 | 08-30-2006 05:39 AM |
| how do i get my script to execute multiple commands? | hvincent | Shell Programming and Scripting | 1 | 04-26-2006 05:19 AM |
| Execute commands parallel in a for loop ? | networkfre@k | Shell Programming and Scripting | 3 | 11-27-2005 04:26 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to execute multiple commands via ssh
I'm having some problem when I'm trying to remote ssh to another server to execute a sql query statement. The main problem lies with the single quotes, it doesn't recognise the single quote in the query.
To my understand, it's the single quote in the sql query that trigger the problem, tried using backslashes but it doesn't work. Any advise will be greatly appreciated. Non working example # /usr/local/bin/ssh -qn [hostname] 'ORACLE_SID=[SID];export ORACLE_SID;ORACLE_HOME=`/usr/local/bin/dbhome lss`;export ORACLE_HOME;$ORACLE_HOME/bin/sqlplus -s [username]/[password]<< EndOfFile > select unique granted_role from dba_role_privs where GRANTED_ROLE='DBA'; > exit; > EndOfFile' select unique granted_role from dba_role_privs where GRANTED_ROLE=DBA * ERROR at line 1: ORA-00904: "DBA": invalid identifier Working example # /usr/local/bin/ssh -qn [hostname] 'ORACLE_SID=[SID];export ORACLE_SID;ORACLE_HOME=`/usr/local/bin/dbhome lss`;export ORACLE_HOME;$ORACLE_HOME/bin/sqlplus -s [username]/[password]<< EndOfFile > select * from global_name; > exit; > EndOfFile' Thanks And Regards Eugene |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Quote:
|
|
#3
|
|||
|
|||
|
Quote:
# /usr/local/bin/ssh -qn [hostname] 'ORACLE_SID=[SID];export ORACLE_SID;ORACLE_HOME=`/usr/local/bin/dbhome lss`;export ORACLE_HOME;$ORACLE_HOME/bin/sqlplus -s [username]/[password]<< EndOfFile > select unique granted_role from dba_role_privs where GRANTED_ROLE="DBA"; > exit; > EndOfFile' select unique granted_role from dba_role_privs where GRANTED_ROLE="DBA" * ERROR at line 1: ORA-00904: "DBA": invalid identifier It gives the same error, but for the sql statement to be valid, I need the single quote. Using backslash >> terminated even before I terminate it. # /usr/local/bin/ssh -qn [hostname] 'ORACLE_SID=[SID];export ORACLE_SID;ORACLE_HOME=`/usr/local/bin/dbhome lss`;export ORACLE_HOME;$ORACLE_HOME/bin/sqlplus -s [username]/[password]<< EndOfFile > select unique granted_role from dba_role_privs where GRANTED_ROLE=\'DBA\'; # |
|
#4
|
||||
|
||||
|
The problem lies in setting right the environment in a different machine using ssh. In your query there are many special characters that need to be escaped, not only single quotes, but backquotes, $ signs, etc....
Example, from server A: Code:
ssh user@serverB "hostname; echo `pwd`" # same thing here for echo $HOME Output ---> name_serverB, /home/dir_serverA and not /home/dir_serverB. Code:
ssh user@serverB "hostname; echo \`pwd\`" Code:
ssh user@serverB <<\EOF your sql query.... ..... ..... EOF Code:
ssh user@serverB <<'EOF' your sql query.... ..... ..... EOF Good luck Last edited by rubin; 08-01-2008 at 10:14 PM. Reason: added additional code |
|
#5
|
|||
|
|||
|
But the scenario works with the a query with no condition (where condition)
eg. Working SQL query select * from global_name; Non-Working SQL query select unique granted_role from dba_role_privs where GRANTED_ROLE='DBA'; Somehow I need to escape the single quote in the select statement if it's possible because of the single quotes in front which is needed to execute multiple commands after I ssh over to the remote host. |
|
#6
|
||||
|
||||
|
Did you try my last suggestion ? I have no problem running commands in a ssh session with the below code that have single quotes in them:
Code:
ssh user@serverB <<\EOF your sql query.... ..... ..... EOF Quote:
Quote:
Quote:
IF condition failing in a SSH script |
|
#7
|
|||
|
|||
|
I need to set the environment variables like ORACLE_HOME, SID without playing around with the user profile, that's why the need to execute multiple commands in the ssh command.
The below work fines given it only execute sql queries. But I still need to set the environment settings. Code:
ssh user@serverB <<\EOF your sql query.... ..... ..... EOF |
|||
| Google The UNIX and Linux Forums |