Using the shell script sql variable

OS: Oracle Linux 5.10

DB Oracle 11.2.0

I have need to query the database and assign the return value to a variable of shell, but it does not work.

create table imr_env (key varchar2(1000), value varchar2(1000) ;
insert into imr_env values('TblspcUsagePct','90');
commit;

Here is the shell script:

#!/bin/bash
echo "in script"
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 ; export ORACLE_HOME
ORACLE_SID=IMR1 ; export ORACLE_SID
export PATH=$PATH:$ORACLE_HOME/bin

pct=`sqlplus -S app/manager <<END
       set serveroutput on
       declare
          output_val number ;
       BEGIN
          select value into output_val from imr_env where key = 'TblspcUsagePct' ;
          dbms_output.put_line('output_val: ' || to_char(output_val)) ;
       END ;
       /
       exit;
END`

## another sqlplus connection, use $pct in the where clause

echo "var value is $pct"

Here is the result:

SQL> ./test.sh
in script
var value is 

output_val: 90

Why isn't the shell variable is populated with the value retrieved from the database?

I need to use $pct in another query that will be storage spaces that are at least 90% full.

I had to change to a korn shell - I couldn't get the "READ" command in shell or bash.

But it is not only "READ" command:

SQL > select * from IMR_ENV;

THE KEY VALUE

------------------------- -----

TblspcWarningLimit 90

TblspcUsagePct 50

SQL > exit

Disconnected from the database to Oracle 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

With partitioning, OLAP, Data Mining and Real Application Testing options

$ cat test.sh

VAL = $(sqlplus-S test/test)<>

Set feedback off

set the position

Select (value) from imr_env, including the key to_number = "TblspcUsagePct";

Select (value) from imr_env, including the key to_number = "TblspcWarningLimit";

"exit";

EXPRESSIONS OF FOLKLORE

)

set $VAL

Echo $1

Echo $2

$./test.sh

50

90

$ echo $SHELL

/ bin/bash

$

Tags: Database

Similar Questions

  • import program does not process customized when you use the shell script

    Hello

    I have the pkg in that

    PROC1 without leaving param in this procedure, I call you created proc2 import and program

    Now, I call this proc1 in the shell script, here my flat program to import does not work

    Why? and I try to use CONSCUB on proc1 using 2 output param which is errbuf, retcode in the newspaper, I'm "wrong number of arguments"

    Please help me?

    Thank you

    Renon,

    Proc1 is your first program at the same time, right?

    How many parameters is defined for that?

    You can paste a screenshot of the window parameter?

    If there is no parameter, just use this:

    $FND_TOP/bin/CONCSUB $LOGIN SQLAP 'Accounts payable Manager' WAIT ' rajesh' = N SIMULTANEOUS SQLAP PROC1

    Assuming that "Renon" is a username of fnd and the program is set in the Application of accounts payable.

    See you soon

    AJ

  • Using the calculation script to write the value of the variable Substitution in a file

    Hello

    I am trying to use the calculation script to write the value of Substitution variable in a text file.
    I use the dataexport command. But it is not able to write values in the text file.

    Any help is appreciated.

    Thank you.

    MaxL would display variable. See: http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/html_esb_techref/maxl/ddl/statements/dispvarb.htm

    BTW, I mostly prefer Esscmd MaxL. I think that makes me a heretic, but I don't understand why I don't want to type more rather than less to get the same result.

    Running a calc:
    Esscmd - RUNCALC 2 calcname
    MaxL - run calculation Sample.Basic.calcname;

    To be fair, Esscmd requires a dbname appname SELECT before the RUNACALC, but it is always less striking.

    However, time is running, so I don't have too. And of course, MaxL now has many things that Esscmd doesn't like Esscmd is obsolete.

    I always use Esscmd to run scripts of calc I can actually watch the output in real time as opposed to MaxL that exports the console at the end of execution.

    Kind regards

    Cameron Lackpour

  • Problem to run the shell script procedure

    Hello

    I wrote a shell script which needs to execute the stored procedure

    The shell script:
    cat bi_loading2.sh
    #!/usr/bin/ksh
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=/u01/app/oracle/product/11.2.0/DWH11gR2
    export ORACLE_SID=DWH
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
    echo "zero  arg  is  :$0"
    echo "First arg  is  :$1"
    echo "Second arg is  :$2"
    
    
    /u01/app/oracle/product/11.2.0/DWH11gR2/bin/sqlplus  system/xxx@dwh << EOF
    insert into SYSTEM.POC_EXDATA_RESULTS  values($1,'$2',sysdate,null);
    commit;
    
    
    execute system.$2;
         
    update SYSTEM.POC_EXDATA_RESULTS
    set end_date=sysdate
    where id= $1;
    
    commit;
    EOF
    exit 0
    The script gets two parameters: id (1) (2) the procedure that I have to run

    As you can see below oracle is to omit the 'run' command
    Please notice why I can't run the stored procedure.


    $ 83 poc_cf54xbx6cchf2 bi_loading2.sh
    zero  arg  is  :bi_loading2.sh
    First arg  is  :83
    Second arg is  :poc_cf54xbx6cchf2
    
    SQL*Plus: Release 11.2.0.2.0 Production on Thu Dec 15 17:46:37 2011
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, Automatic Storage Management and Real Application Testing options
    
    SQL> 
    1 row created.
    
    SQL> 
    Commit complete.
    
    SQL> SQL> SQL> BEGIN  system.poc_cf54xbx6cchf2; END;
    
                    *
    ERROR at line 1:
    ORA-06550: line 1, column 17:
    PLS-00103: Encountered the symbol "SYSTEM" when expecting one of the following:
    := . ( @ % ;
    The symbol ":=" was substituted for "SYSTEM" to continue.
    
    
    SQL> SQL>   2    3  
    4 rows updated.
    
    SQL> 
    Commit complete.

    Read the error stack.

    ORA-06512: at "SYSTEM.POC_CF54XBX6CCHF2", line 3
    

    The error is on line 3 of the POC_CF54XBX6CCHF2 procedure
    If the procedure is called.

    ----------
    Sybrand Bakker
    Senior Oracle DBA

  • How can I use the shell only for hyperterminal on Vistas part

    I need to use the shell for hyperterminal.  I was told that Vista does not support the hyperterminal.   What are my options?  How can I access the command line?

    Alternatives to HyperTerminal in Vista
    http://www.windowsreference.com/Windows-Vista/alternatives-to-HyperTerminal-in-Vista/

    http://www.Google.com.au/search?q=HyperTerminal+on+Vista&SourceID=IE7&RLS=com.Microsoft:-to the: IE-SearchBox & ie = & oe = & redir_esc = & ei = bZOWS7unFcuLkAWAg4ywCg

    To access the command prompt type cmd in the box Start Menu search.  If you want to run it as an administrator, you will need to click on it, then select this option?

  • How to use the Shell of the user interface with multiple applications (ear)

    I use 11.1.1.6 JDeveloper.

    I want to modularize the functionality in applications (ears) and use the Shell of the user interface as a navigation mechanism between applications and single entry.

    Is this good?

    What is the use of Shell of the user interface best practices.

    What about security (2 AA)? Security of the ADF?

    Thank you

    Hi user,

    You can use the shared library ADF function if you would like more information

    http://andrejusb.blogspot.AE/2010/07/deploying-ADF-applications-as-shared.html

    use the adf security

  • Can we use the value of a variable in a warning message

    I have a variable in forms6i. I want to use the value of this variable in an alert message. How is that possible?

    Gul says:
    I have a variable in forms6i. I want to use the value of this variable in an alert message. How is that possible?

    Try

    DECLARE err_txt VARCHAR2(200) t;
     al_id ALERT;
     al_button Number;
    BEGIN
    al_id := FIND_ALERT('My_Error_Alert');
    SET_ALERT_PROPERTY(al_id, alert_message_text, 'Hello how are you mr. variable '||:variable_name );
    al_button := SHOW_ALERT( al_id );
    END; 
    

    Hope it works...

    Hamid

  • Can I use the .jsx scripts that use with CS6 with Photoshop Elements?

    I have a series of scripts I use at work and have access to Photoshop CS6. I have Photoshop elements 12 at home and I wonder if I can use the same scripts.

    Thanks for any help!

    You can run the same scripts in ESP 12, but they can not work if they use functions is not only pse 12.

    You can test using file > Open in EPS 12 and then choose the script.

    Since 12 PES doesn't have a file > Scripts menu, but uses the file > menu instead, automation tools then you might need to modify the script (javascriptresource) to only show the menu of automation tools.

    Or save some actions which are pointing to the script (s)

  • Use the same script in different areas?

    Is it possible to use the same script in different areas?

    I had several scripts that will validate and modify the entries in the user on different areas. Since they do exactly the same thing, is it not possible to just get out the 'real' on a field script and refer to other fields to this script?

    Of course - we have a fragment of 'commonScriptObjects.xdp' that we all have

    our common methods of javascript in.  Then we add to the form and hide it.

    then use the following reference to point to the script object:

    GET A HANDLE TO THE SCRIPT OBJECT

    var commonScript =

    xfa.resolveNode ("commonScriptObjectsFrag.fragmentScript");

    CALL A JAVASCRIPT METHOD IN THE SCRIPT OBJECT

    commonScript.setupSearch ();

    Here's something else you can do to validate our mandatory fields.  We spend in

    the real to validate field and the name of the field as a text string:

    If (! commonScript.validateRequired (mainContentSubform.customerName,)

    False return 'Customer'));

    and the validateRequired method, which is in our commonScriptObject xdp

    file, looks like this:

    validate required fields

    function validateRequired (oField, fieldName) {}

    Console.println ("enter validateRequired");

    var commonScript =

    xfa.resolveNode ("commonScriptObjectsFrag.fragmentScript");

    If (commonScript.isNullValue (oField.rawValue))

    {

    xfa.host.messageBox ("Please fill out the '" + fieldName +)

    ("' field.", "Error", 3);

    xfa.host.setFocus (oField);

    Returns false;

    }

    Returns true;

    }

    Hope that helps,

    Elaine

    ocen12 [email protected]>

    29/07/2009 09:26

    Please respond to the

    [email protected]

    TO

    Amal [email protected]Schmitz >

    CC

    Object

    Use the same script in different areas?

    Is it possible to use the same script in different areas?

    I had several scripts that will validate and modify the entries in the user on

    different areas. Since they all do exactly the same thing, is not

    possible to just get out the 'real' on a field script and refer to the

    other areas of this script?

  • Need to call the Shell script that uses SQL loader in APex4.1 / 11g

    Hello!

    I have a requirement in which I need to call a shell script that connects to an external server, FTP to a file and then use sqlloader to load data into our table. We have now the ftp script that accomplishes this task to another program, but is a scheduled task. I wanted to call the script ftp in the APEX. Any suggestions on how this can be done, what is the logic of PL/SQL can we use? I saw online some people using DBMS Scheduler for this?

    Thank you
    Sun

    Hello

    Create some sh script on your computer host oracle where you can join in the external server and run the process.
    something like:

    run_external_sh.sh

    #!/bin/sh
    ssh ext_user@ext_host ./sqlloader/import/import.sh
    

    Then create an external TASK to call it via ORACLE (PL/SQL)

    -Shell Script call.

    BEGIN
      DBMS_SCHEDULER.create_program (
        program_name        => 'external_call_sh',
        program_type        => 'EXECUTABLE',
        program_action      => '/local_host/call_external/sh/run_external_sh.sh',
        number_of_arguments => 0,
        enabled             => TRUE,
        comments            => 'Call external SH script');
    END;
    /
    

    You can now create a regular / or unplanned WORK
    -Job defined by the calendar and an existing program.

    BEGIN
      DBMS_SCHEDULER.create_job (
        job_name      => 'jb_external_call_sh',
        program_name  => 'external_call_sh',
        schedule_name => 'external_call_scheduler', -- created scheduler
        enabled       => TRUE,
        comments      => 'Job defined by an existing external_call_sh program and schedule.');
    END;
    /
    

    You can now call the WORK in the APEX in the process of PL/SQL.

    BEGIN
      -- Run job synchronously.
      DBMS_SCHEDULER.run_job (job_name            => 'jb_external_call_sh');
    END;
    

    Concerning
    J :D

  • Pass the Shell script variable to the plsql block

    Hello
    I have a shell script and pass the parameter of Shell script in a PLSQL block, I use the code but impossible to get any result, below
    Can someone help me with this issue?

    Shell script: test.sh


    * #! / bin/sh *.

    var1 = $1

    SQLPLUS = 'sqlplus-s ".
    Login = "gmisowner/gmisowner1".

    day ='$SQLPLUS $LOGON < < ++
    set the position
    Set feedback off

    Start
    select count () from mis_ref_codes where ref_description = & var1; *

    end;

    "exit";
    ++`

    echo $day

    Execution at the command prompt: >./test.sh Underline
    returns nothing

    1. I was hoping the count (*) in the number of lines in him select statement is stored in the day, but nothing returned as output of the plsql block
    the select statement above is an example, but I'll have to run a much larger plsql block

    I have syntactically doing something wrong? Please suggest

    Published by: Camilla January 14, 2012 12:35

    First of all you needget get rid of anonymous PL/SQL block:

    var1=$1
    
    SQLPLUS="sqlplus -s"
    LOGON="gmisowner/gmisowner1"
    
    day=`$SQLPLUS $LOGON <<++
    set heading off
    set feedback off
    select count(*) from mis_ref_codes where ref_description=&var1;
    exit;
    ++`
    echo $day
    

    But it still does not work. Your SQL * more script a proxy & var1. It has nothing to do with shel environment variable var1. That is why SQL * PLus prompts you to enter the value just after she readings

    Select count (*) in the mis_ref_codes where ref_description = &var1;

    And since you redirected input to your script, you must put value of var1, which isn't what you want, right? So what you need is:

    dev > # I'll set $1 to X
    dev > set X
    dev > var1 = $1
    dev > SQLPLUS = 'sqlplus-s ".
    dev > login = ' / '.
    dev > ='$SQLPLUS $LOGON < < EOF
    > set position
    > leave your comments
    > set verify off
    > select ' Have a nice day! "twice where dummy ="$var1 ";
    > "exit";
    > EOF'
    dev > echo $day
    Good day!
    dev >

    SY.

    Published by: Solomon Yakobson on 13 January 2012 15:17

  • Call the batch file and not the shell script using measures of the event

    Can I use EVENTACTIONS at the door of gold like

    eventactions (SHELL, /path-to-batch-file/test1.bat)

    will this work? I am on a windows machine, so I need to run a batch file and not a shell script

    In GGSCI, you can shell OUT to the BONE and call a command/executable file.

    For example on Windows:

    GGSCI (WIN2003) 2 > shell dir

    Volume in drive C has no label.

    Volume serial number is 8CCC-9E58

    Directory of C:\ggs

    18/08/2012 07:23

    .

    18/08/2012 07:23

    ...

    2010-10-15 06:37 bcpfmt.tpl 426

    2010-10-15 06:37 bcrypt.txt 1 725

    22/04/2011 03:41 2 560 category.dll

    05/11/2011 10:43

    cfg

    2010-10-15 07:15 739 chkpt_ora_create.sql

    ...

    What were the results when you tried this in an EVENTACTIONS clause?

  • Permission denied error when you use the Matlab script

    I have the following simple running a Matlab script in Labview.

    K = 5;
    Matrix = randn (4,4);
    matlab.io.saveVariablesToScript ('Parameters.m', {'K', 'Matrix'})

    the last command saves the variables 'K' and 'Matrix' in the m-settings file that I can then use to load the settings 'K' and 'Matrix' to a 'Control Design and Simulation Model'.

    When I run the now from Matlab everything works fine. When I run this LabVIEW so I get the following error:

    LabVIEW: An error has occurred during execution of the script. Error message from the server?: Error using matlab.io.saveVariablesToScript
    Parameters.m: Could not open the file: permission denied.

    I use Matlab 2015 and LAbview 2015 in a 64-bit windows computer 7.

    Any help would be really appreciated.

    For those who have the same permission denied errors, I found the solution.

    I had to specify the current working directory in the matlab script (this is the directory to which you saved your LAbview VI).

    For example, if you have saved your labview vi to C:\Example_Folder

    then you must add the following command in your matlab script node before the command that causes the error

    CD (' c:/Example_Folder')

    I hope this will help.

  • PowerShell to execute the shell script in Linux guest

    Is there a way of powershell to access a Linux VM in a domain environment and then run a Linux shell script to a guest Linux OS - for example to set the network settings of the virtual machine?

    Thank you!

    You can use the Invoke-VMScript cmdlet. It allows you to run a script bash inside the Linux guests supported.

    There is also the Set-VMGuestNetworkInterface cmdlet to configure NETWORK card. It is based in fact on the same technique as the Invoke-VMScript cmdlet, but PowerCLI Dev team provided the bash script to you.

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • 12 c: SOA deployment using the ANT script

    We seek to deploy a composite SOA 12 c using the Ant.. As a first step, we use "Ant-sca - package.xml ' to create the package and then deploy using the file" Ant-sca - deploy.xml. One of the properties required by the script is "compositeDir". When we set this value to the composite directory, we get an error composite.xml is missing. And if you change its value in the "soa" with composite directory folder, it works.

    Confirmation, as what value need to affect the property "compositeDir".

    Thank you

    compositeDir is the absolute path of the directory that contains composite.xml, then you must set the property compositeDir as baseDirectory/SOA.

    For a question related to the location of the jar file, there is a known issue already documented here: Known Issues for Oracle SOA products

    Check the details under the heading: "Oracle JDeveloper and ant control Deploy SAR files in different directories;

Maybe you are looking for

  • SYTEM RESTORE BACK TO FF4... FF5 CRASHING COMPUTER

    I THINK THIS SAYS ALL... JKR

  • iPod Classic FREEZES up

    I have and have had several classic iPod.  I started with the 40G iPod with click wheel and I think I'm going on my fifth 160G iPod Classic.  I currently own a 160G iPod Classic, iPhone G 128, 6 +, an 80G Classic iPod, iPod Touch 64G and an iPod 30G

  • the hotel boat

    Can I order a laptop on the address of the hotel?And if I can pay cash to get the parcel?I don't have a GSM local phone network if you can take the international registration number when sending?

  • DM1 login

    Can someone advise how I turn on without having to connect. My netbook is blocked and I therefore don't require this additional level of security See you soon

  • Computer to close after pressing the close button in windows

    I had a problem for my computer to shut down after pressing the close button in windows. Windows starts to make the closing process as its suppose there just like the computer is supposed to to close it restarts. Its like I pressed the button instead