ssh with special character to sqlplus

Posted on 2014-07-13
Last Modified: 2014-07-14

In Linux RHEL 5.6
I'm trying to execute a SQL statement inside Oracle on a remote host.
My query is using the v$parameter and I'm having problems passing the $(dollar sign).

My code:
> RESULT=`ssh  "setenv ORACLE_SID $PRIMARY_ORACLE_SID; sqlplus -s / as sysdba << EOF
    select value from v$parameter where name='dg_broker_start';
 RESULT= select value from v where name='dg_broker_start'

I tried "v$parameter"
and      v\$parameter
and    "v\$parameter"

none of the above worked.
Only the V is left...
Question by:peledc
    LVL 68

    Expert Comment

    You'll have to use at least two backslashes for escaping - the $ sign must be protected from being expanded by the local shell as well as from the remote shell.

    If two backslasehs don't work either try three of them (at least I once had to do so to make it work).
    LVL 76

    Expert Comment

    if I'm not mistaken, you may have to use v\\\$
    the first will be drawn down to v\$

    If this is a common query, why not setup a script on the remote end to which you will be passing data points?
    LVL 68

    Accepted Solution

    Three backslashes are not sufficient for ssh/sqlplus between backticks.

    Try  v\\\\\\$parameter

    No joke!
    LVL 19

    Expert Comment

    You could also try 1 (or 3) backslashes between the << and the EOF (immediately before the E of EOF).
    LVL 1

    Author Closing Comment

    This worked \\\\\\


    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
    Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now