![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Execute db2 commands in unix | rollthecoin | AIX | 3 | 04-26-2008 01:17 AM |
| lom don't execute commands | pasalagua | SUN Solaris | 6 | 01-25-2008 04:22 PM |
| Can Xargs execute multiple commands of evry input file | nilesrex | Shell Programming and Scripting | 4 | 08-30-2006 08:39 AM |
| how do i get my script to execute multiple commands? | hvincent | Shell Programming and Scripting | 1 | 04-26-2006 08:19 AM |
| Execute commands parallel in a for loop ? | networkfre@k | Shell Programming and Scripting | 3 | 11-27-2005 07:26 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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\'; # |
|
|||||
|
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-02-2008 at 01:14 AM.. Reason: added additional code |
|
||||
|
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. |
|
|||||
|
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 |
|
||||
|
Some environment thingy causes the execution problem somewhere *I Guess*.
Given the same script, I execute it as 2 different OS user, Script as follor: Code:
# more t.sh #!/bin/ksh OracleLoginUsername=[Username] OracleLoginPassword=[Password] QueryStatement=`/usr/local/bin/ssh -qn [Hostname] "cd /usr/local/scripts/user_admin;export ORACLE_SID=[SID];export ORAENV_ASK=NO ;. /usr/local/bin/oraenv;$ORACLE_HOME/bin/sqlplus -s $OracleLoginUsername/$OracleLoginPassword << EndOfFile @/tmp/CheckUser.sql [Parameter] EndOfFile"` UserName=$(echo $QueryStatement) echo $UserName As Root User # ./t.sh sh: ORACLE_SID=lss: is not an identifier As another OS User # ./t.sh [Returned Result successfully] |
![]() |
| Bookmarks |
| Tags |
| unix commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|