Calling sqlplus from unix script

hello,
I am trying to connect to sqlplus from shell:
#!/bin/bash
SERVER_NAME=ORA1
sqlplus -s SYS/PASSWD@$SERVER_NAME AS SYSDBA <<EOF
select * from v\$version
EOF
However, the output is:
Usage: SQLPLUS [ [<option>] [<logon>] [<start>] ]
where <option> ::= -H | -V | [ [-L] [-M <o>] [-R <n>] [-S] ]
<logon> ::= <username>[<password>][@<connect_string>] | / | /NOLOG
<start> ::= @<URI>|<filename>[.<ext>] [<parameter> ...]
"-H" displays the SQL*Plus version banner and usage syntax
"-V" displays the SQL*Plus version banner
"-L" attempts log on just once
"-M <o>" uses HTML markup options <o>
"-R <n>" uses restricted mode <n>
"-S" uses silent mode
Do you have any idea about that?
Thanks.

the connection was establised. thanks.
any idea why I am getting the same output twice for the following statement?
#!/bin/bash
ORACLE_SID=ORA1
export ORACLE_SID
sqlplus -s SYS/PASSWD@$ORACLE_SID AS SYSDBA <<EOF
select SUM(bytes) from dba_data_files where tablespace_name = 'tts1';
EOF
the output is
SUM(BYTES)
3.4773E+10
SUM(BYTES)
3.4773E+10

Similar Messages

  • Calling sqlplus from shell script

    Hi ,
    I am calling sqlplus from a shell script. After running sql commands successfully, it fails to continue executing commands from the shell script.
    There is no EXIT statement at the end of the sql.
    The error i get is,
    SP2-0734: unknown command beginning "echo "FFFF..." - rest of line ignored.
    Can someone please help.

    how does your shell script looks like? did you check my other post today on this forum
    sqlplus called from a shell script

  • How to get an error code from from calling sqlplus from shell script?

    Hello -
    i am calling sqlplus from a bash shell script. If the sql statement generates an error, how can I return that error code (unsuccessful) back to the bash shell?
    Thanks!

    user11340104 wrote:
    Hello -
    i am calling sqlplus from a bash shell script. If the sql statement generates an error, how can I return that error code (unsuccessful) back to the bash shell?
    Well, let google be your friend,
    http://www.google.co.in/search?rlz=1C1GGLS_enIN327IN327&sourceid=chrome&ie=UTF-8&q=sqlplus+error+codes
    There are many threads I guess talking about the same issue.
    HTH
    Aman....

  • Calling maxl from unix script

    Hi guys..I want to call a maxl script from a unix script. i am using ksh shell in unix..
    Can anyone give me the syntax from this..I am not very familiar with this.

    Actually I found there was an Esscmd.sh file too.that's why wanted to be sure about the option of esscmd.
    And would these scripts accept parameters like this:
    <path>Middleware/user_projects/epmsystem1/EssbaseServer/essbaseserver1/bin/startMaxl.sh /maxl-Path/script.mxl 1 2
    and if we place & after the script name would it be a nohup process and run the next ones parallely??:
    <path>Middleware/user_projects/epmsystem1/EssbaseServer/essbaseserver1/bin/startMaxl.sh /maxl-Path/script1.mxl &
    <path>Middleware/user_projects/epmsystem1/EssbaseServer/essbaseserver1/bin/startMaxl.sh /maxl-Path/script2.mxl &
    Sorry if my questions seem stupid.
    I know very little about this tech and just want to clear any confusion and know as much as i can.

  • Calling sqlplus from unix shell script

    Hi All,
    I am executing the following code :-
    sqlplus -s ${DATABASE_USER} |&
    print -p -- 'set feed off pause off pages 0 head off veri off line 500'
    print -p -- 'set term off time off serveroutput on size 1000000'
    print -p -- "set sqlprompt ''"
    print -p -- "SELECT run_command from tmp_run_batch where upper(batch_name) = upper('${PAR_PROGRAM_NAME}');"
    read -p RUN_COMMAND
    eval print -p -- \""execute dbms_output.put_line(${RUN_COMMAND});"\"
    read -p RET_VAL
    print -p -- "exit;"
    The select stmt given above gives sample output as :-
    pack_claims_clas_utils.func_main('$PAR_RUN_DATE','$PAR_RUN_LEVEL','$PAR_EXCLUSIVE_RUN_YN')
    And then this package is executed.
    The problem that I am facing is how to handle the no_data_found case of the select stmt. . When this case arises then the stmt. "read -p RUN_COMMAND" hangs.
    Could you please provide any solution ?
    Thanks
    Suds

    Hi,
    Have you tried this:
    # if [ -n means String has non-zero length
    if [ -n $RUN_COMMAND ]
    read -p RUN_COMMAND
    fi
    Hi All,
    I am executing the following code :-
    sqlplus -s ${DATABASE_USER} |&
    print -p -- 'set feed off pause off pages 0 head off veri off line 500'
    print -p -- 'set term off time off serveroutput on size 1000000'
    print -p -- "set sqlprompt ''"
    print -p -- "SELECT run_command from tmp_run_batch where upper(batch_name) = upper('${PAR_PROGRAM_NAME}');"
    read -p RUN_COMMAND
    eval print -p -- \""execute dbms_output.put_line(${RUN_COMMAND});"\"
    read -p RET_VAL
    print -p -- "exit;"
    The select stmt given above gives sample output as :-
    pack_claims_clas_utils.func_main('$PAR_RUN_DATE','$PAR_RUN_LEVEL','$PAR_EXCLUSIVE_RUN_YN')
    And then this package is executed.
    The problem that I am facing is how to handle the no_data_found case of the select stmt. . When this case arises then the stmt. "read -p RUN_COMMAND" hangs.
    Could you please provide any solution ?
    Thanks
    Suds

  • Triggering background job event from Unix script

    Hi all,
      I am having one question regarding triggering of background job in SAP using Events from Unix script. Is this possible? If so, can anyboy provide some sample code related to Unix script and how do we communicate to SAP from Unix system. Actually, here the backend of R/3 system is MSSQL. I am having a program in R/3 system which is scheduled as a background job based upon event trigger. I want to trigger that even from the unix script.
      Appreciate for your help in advance.
    Thanks,
    Adithya K

    Hi,
    Check if this can help you
    http://help.sap.com/saphelp_sm32/helpdata/en/fa/096e6b543b11d1898e0000e8322d00/content.htm
    Regards,
    Atish

  • Call ABAP program from Unix script passing dynamic filename

    Hi,
    Does anyone know if it is possible to call an ABAP program from a Unix script passing a dynamic filename to the ABAP program?
    We are receiving a file from an external company and on receipt of the file want to call an ABAP program passing the filename.  The filename is made up of File ID, Date and Time which we need to read in the ABAP program.  We usually use Events to trigger a program which is fine when the filename if static however since this filename will be dynamic we cannot do this.  In addition we cannot just rename the file to a static name in the Unix script as we need to know the value of the date and time from the file ID in the ABAP program.  I can change the ABAP program to check our /in directory for a Filename that starts with the fixed File ID however I thought there must be a better way of doing this.  We want the external company to put this information in a file header record but they don't want to change the file contents.  Any ideas would be appreciated.
    Thanks,
    Sinead.

    You could follow the following method
    1.Let the external file reside in the SAP application layer in a defined path e.g. /usr/sap/tmp/interface/working/
    2.Write an ABAP program which will include the following steps:-
       i) read all files in the file path using function module EPS_GET_DIRECTORY_LISTING
      ii) Read the data from files existing in the directory using OPEN_DATASET statement
    iii) After the files have been read move the files to another directory e.g. /usr/sap/tmp/interface/backup/ or you can delete the file.
    3.Schedule this program to be executed depending on the frequency of the external file being generated.

  • Running SQLPLUS from UNIX shell script

    I'm not sure if this is the right forum, but...
    How can I execute a sql file from inside the UNIX shell script, logging on to Oracle w/o supplying a UID/pwd? Normally, we log into UNIX using our own logon, then sudo as another user to login to Oracle. Now, I'm trying to create a UNIX shell script, where I'm already sudo'd as the UserID that logs into Oracle. I've tried the following, but can't get it to work. I'm a UNIX scripting noob. Any ideas?
    example:
    #! /usr/bin/ksh
    sqlplus / \@test.sql << EOF
    exit;
    EOF

    I'm a UNIX scripting noob.In which case I feel obligated to point you at William Robertson's excellent article Database Shellscripts Considered Harmful. Save yourself a world of pain.
    Cheers, APC

  • Problem while calling concsub from shell script

    Hi All,
    I am facing problem when I am trying to run CONCSUB utility from shell script.The same works well when I try it from command line.The only prob I am facing from shell script is assigning values to temporary variables.
    This is how my script looks
    #!/bin/bash
    export PARM5="$5"
    export PARM6="$6"
    export PARM7="$7"
    echo "INTPARM5=\"$PARM5\""
    echo "INTPARM6=\"$PARM6\""
    echo "INTPARM7=\"$PARM7\""
    echo $FND_TOP/bin/CONCSUB $1 ONT 'Order Management Super User, Vision Operations (USA)' $3 WAIT=Y CONCURRENT ONT $PROGRAM "$INTPARM5" "$INTPARM6" "$INTPARM7"When I try to run the above shell based concurrent program it doesn't pass the parameters as expected and it errors out saying "Wrong number of arguments to call the procedure"
    I tried my luck from some of the previous posts ({thread:id=2360776} ),but to vain
    If anyone has any ideas,please suggest!!
    Thanks in advance!!
    Edited by: sandy on May 4, 2013 12:54 PM

    Here are your proofs
    Proocedure
       PROCEDURE abc(--p_errbuf            OUT   VARCHAR2,
                                                --p_errcode           OUT   VARCHAR2,
                                 p_order_no          IN    NUMBER DEFAULT NULL,
                                                p_customer_id       IN    NUMBER DEFAULT NULL,
                                 p_name              IN    VARCHAR2 DEFAULT NULL
          IS
                    v_cname    VARCHAR2(200);
               v_ordered_date DATE;
               v_order_number  NUMBER;
              v_order_type    VARCHAR2(200);
    BEGIN
                fnd_file.put_line(fnd_file.output, 'Begin Execution');
       SELECT DISTINCT ac.customer_name,
                    d.ordered_date ordered_date,
                    d.order_number order_number,
                    x.NAME order_type
            INTO   v_cname
               ,v_ordered_date
               ,v_order_number
               ,v_order_type
               FROM oe_order_headers_all d,
                    oe_transaction_types_tl x,
                    wsh_delivery_details b,
                    wsh_delivery_assignments c
                    ,ar_customers ac
              WHERE 1 = 1
                AND ac.customer_id = b.customer_id
                AND d.order_type_id = x.transaction_type_id
                AND x.LANGUAGE = 'US'
                AND b.released_status = 'B'
                AND b.source_header_id = d.header_id
                AND c.delivery_detail_id = b.delivery_detail_id
                AND d.order_number=NVL(p_order_no,d.order_number)
                AND ac.customer_id = NVL(p_customer_id,ac.customer_id)
             AND x.name=NVL(p_name,x.name)
                AND NOT EXISTS (SELECT 1
                                FROM wsh_delivery_details b
                               WHERE 1 = 1
                                      AND b.released_status != 'B'
                                      AND b.source_header_id = d.header_id)
                                       --BETWEEN ('1213794') and ('1213797'))
                AND rownum<2;
            INSERT INTO xxc_temp(customer_name,ordered_date,order_number,order_type) VALUES(v_cname,v_ordered_date,v_order_number,v_order_type);
            COMMIT;
             fnd_file.put_line(fnd_file.output, 'Order Number is' || v_order_number);
             fnd_file.put_line(fnd_file.output, 'Order Type is'   || v_order_type);
       END;Script
    #!/bin/bash
    set -x
    export PARM5="$5" 
    export PARM6="$6"
    export PARM7="$7"
    sqlplus -s $1 <<EOF
    set head off feed off serverout on size 1000000
    exec abc('$PARM5','$PARM6','$PARM7');
    exit
    EOFNow when I run the 'XX Order Detail CSV Report' I get the below log and no Output
    +---------------------------------------------------------------------------+
    Application Object Library: Version : 12.0.0
    Copyright (c) 1979, 1999, Oracle Corporation. All rights reserved.
    XXKES_PDF_TRANSFER module: XX Order Detail CSV Report
    +---------------------------------------------------------------------------+
    Current system time is 06-MAY-2013 05:05:56
    +---------------------------------------------------------------------------+
    + export PARM5=66432
    + PARM5=66432
    + export PARM6=
    + PARM6=
    + export PARM7=Mixed
    + PARM7=Mixed
    + sqlplus -s APPS/APPS
    +---------------------------------------------------------------------------+
    Executing request completion options...
    Output file size:
    0
    +------------- 1) PRINT   -------------+
    Disabling requested Output Post Processing.  Nothing to process.  The output of the request is zero byte.
    +--------------------------------------+
    Finished executing request completion options.
    +---------------------------------------------------------------------------+
    Concurrent request completed successfully
    Current system time is 06-MAY-2013 05:05:56
    +---------------------------------------------------------------------------+After the concurrent program executed I queried the table xxc_temp and here you see the data
    SQL> select * from xxc_temp;
    CUSTOMER_NAME
    ORDERED_D ORDER_NUMBER ORDER_TYPE
    A. C. Networks
    18-FEB-13        66432 MixedMy procedure fetches the data fro given set of i/p parameters but it doesn't give o/p coz it's a host based conc program.Please advise if there's a way to get the o/p in a host based conc program
    Thanks!!

  • How to call pakage using Unix script

    Hi,
    I have created one package in Oracle(contains2 funcation and 4 procedure) which is in in xxx14database.
    Now i can execute the package and its working fine at database level.
    As per requirement ,i need to create on Unix script to trigger the package.
    I have no idea how to create the Unix script to execute the package.
    The Unix script need to created in xxxx001 Server.
    Can anyone please let me know the template or any link which I can refer to create the same.
    Or anyway i can create a script/batch on window and test first in my laptop and use the same script for my project work with required modification
    Secondly the application owner asked me to give them both database and Unix script to them so that their database team will test the Package which i developed.
    Database script meand the Package body and spec i should save as file.pkb format and send them or i can save them in .sql file and send them
    Thanking you all in advance please help its urgent.

    Now that you know how to do it ... reconsider whether doing so is a good idea.
    There is almost nothing you can do calling from a shell script that can't be done more easily from DBMS_SCHEDULER other than compromise security. Shell scripts connecting to the database are, as shown in the demo code, inherently insecure and, if you get enough of them, make it difficult to cycle passwords on a regular basis.

  • Calling java from csh scripts

    I have recently come across certain projects where Java has being used as an alternative for scripting purposes. What I am trying to say here is that making calls to java programs from csh scripts and these Java programs are merely doing trivial/sql tasks which could have very well been carried out in a scripting language itself. and then Java calling some scripts so ending up with a chain of Java calling scripts which call Java and so on.
    It has been my understanding all along that such a design would not be something recommended, and there should be a separation of concerns and a clear demarcation between Java and the scripting code. What however I am struggling with is finding some articles or papers supporting this thought and I would greatly appreciate if some you have something you would like to share preferably an article, supporting or negating such a design.
    Edited by: kilyas on Mar 25, 2010 2:52 PM

    >
    Actually my original post was a reply to Saish. But thanks for the input. It's good to know that you extend TDD to scripting as well, but most of the scenarios I have come across thats not been the case. Whether thats the lack of test tools/libraries like JUnit or JMock for csh scripting or the user's frame of mind of getting things done, I am not sure.There's no need for such tools. Even in Java et al, test harnesses can be hand-whittled. JUnit is just Java code, after all. Test harnesses for scripts are no different. As an extremely basic example, you might a file that picks up everything from one directory, run a sed application against it, and dump the results in another directory. Writing tests for that is pretty easy; start with a couple of sample input files, and expected outs, apply your script, do a diff on the resut against the expected outs. Granted there isn't a nice UI to give you a green bar with shell scripts, but you can still get a list of pass/fail stats. Groovy scripts, of course, can be run in an actual JUnit runner.
    If you're finding it too hard to test scripts, like perhaps there are too many different flows of execution through the script, it's worth considering whether the task-at-hand is really a scripting job at all. The sweet spot for scripts is gluing together the stuff that performs all the complex logic.
    What are the best practices recommendations for such a scenario, I am sure there much be something about it or some pattern or anti pattern dealing with it and some review of such an implementation. Don't you think so?I hope so! I've been tasked with documenting a scripting standard written by another developer, finding references to cite and such-like. There do exist coding standards on the web for scripting, shouldn't be too hard to find something useful. As for reviews, I expect simple peer review by someone else who knows scripting is about as good as it's going to get.
    I'd add that logging plays an important part in scripting, just as it does in your "real" code

  • How to invoke from UNIX script and pass back return code?

    Though I am an experienced developer, I am new to java. I created a class containing a single method. I have performed my testing by running the class class.method from the command line in a UNIX (Solaris) environment. Now, I would like to have the class.method invoked from a UNIX shell script, and to return a success/failure indicator from the method, to the UNIX script. I modified the method to make it return char, rather than being defined as void. Within the class and method, I declared and initialized a char variable. I added a finally clause which contains a single return statement, returning the char return code variable. Within my UNIX script, I invoke the class/method as follows:
    return_code = java myClass
    This does not seem to be invoking the method however. Can someone please tell me what I am doing wrong? Or is more information needed in order for someone to help me out.
    Please let me know.
    Thanks.
    Brad

    stdunbar,
    Using your suggestion of System.exit(retVal); seems to allow the java method to be performed successfully (Thank You). But I am still having a problem with the value being recognized by the shell script.
    In my script, I'm doing the following:
    java MyClass inputparameter > return_code
    export return_code
    echo $return_code
    But return_code does not seem to contain a value. Just before the System.exit(retVal); I added System.out.println("return code = " + retVal ); and I can see that retVal. When I run the java method outside of the UNIX shell script, I can see that retVal does indeed contain a value. So I think my problem might actually be the code in the UNIX script.
    Thanks again.
    Brad

  • Raise alert from Unix script

    Hi,
    I have a scenario where my post processing Unix script would append 5 individual files to create a master output file. If everything works fine, well and good. In case of any error - XI has to raise an alert to the support team. Could you please let me know how this can be done. I assume that the Unix script should be coded such a way so that it raises an alert if something fails in its processing logic. Could you please let me know how to do this? Any sample Unix script would also be highly appreciated.
    Thanks in Advance,
    Santhosh

    Hi Prateek,
    Many thanks for yor response. I was also thinking on this approach - but i didn't want to add on another file based interface to the existing set of all file based (all this problem is coz of this file based integration) interfaces. This would be my last option.
    is there any other way to directly trigger an alert thru unix command prompt?
    Btw :- Many thanks for your reference to the blog.
    Regards,
    Santhosh M.

  • Calling sqlplus from trigger

    hi -
    I am trying to call a sql script in a trigger. I am trying to pass a parameter to the script but when the sql runs - it doesn't
    recognize the parameter. I am probably making a very simple mistake - but I am new
    to Forms development.
    Here is my code:
    DECLARE
    CURSOR sheet_docs_cur IS
    SELECT doc_num
    FROM SNAP_DOCS
    ORDER BY DOC_NUM;
    BEGIN
    FOR snap_rec IN sheet_docs_cur LOOP
    HOST('sqlplus user/password@db
    @R:\TEST.sql '&#0124; &#0124;snap_rec.doc_num);
    END LOOP;
    END;
    What have I done wrong ? Thanks....
    null

    Hi, everyone.
    Yes, you can pass parameters to SQL*Plus script file, but only if the parameters are called &1, &2, etc...
    So, if you test.sql is:
    set verify off
    select * from table where doc = &1;Then you can call it using:
    HOST('sqlplus user/password@db @R:\TEST.sql '&#0124; &#0124;snap_rec.doc_num);and &1 will be replaced by snap_rec.doc_num.
    There are also a few posts on this subject right here, on this forum. All you have to do is search a little.
    Hope this helps,
    Pedro

  • Tcl proc with input argument run from UNIX script...how

    Environment:
    OWB 10g Client on Windows XP Professional
    Repository - 9.2.0.4 on UNIX (AIX 5.2)
    Target - 9.2.0.4 on UNIX (AIX 5.2)
    I need a little tcl advice, please!
    I have a tcl script (proc, I guess) that takes one argument, in this case a mapping name.
    I would like to execute this tcl script from a UNIX shell script and pass the name of the mapping as an argument to the UNIX shell script. Something like:
    OMBPlus.sh omb_deploy.tcl $1
    where omb_deploy.tcl is the script that has all the OMBPlus commands in it to create the deployment plan and execute it.
    I'd like to pass the mapping name as a command line argument to the UNIX shell script but it doesn't like it.
    When I execute the script as above, I don't see any output and the mapping does not get deployed.
    So, I need a little help on two (2) issues:
    1- How do I generate a log file of the output of the tcl script?
    2- How do I pass the mapping name as an argument to the UNIX shell script?
    For #1 I have tried using the 'open logfilename w' at the top of the tcl script but it produces no output.
    I saw another example from this forum where the author used a 'putslog' command in the script. I can't find any documentation on that command, what does it do?
    That same script set a global OMBLOG variable at the top of the script and used the 'putslog' command in the body.
    Is OMBLOG some special reserved word for logging? I couldn't find anything on it.
    I'm trying to learn tcl but struggling to put all the tcl stuff together with all the OMBPlus stuff and make it all work is getting the best of me.
    Any assistance, with examples (I learn best from them), is greatly appreciated.
    Gary

    Well duh!
    I ended up just logging everything from the UNIX shell script and letting the tcl script write everything to stdout.
    I also finally found the $argv parameter and have used that to pick up the name of the mapping being passed to OMBPlus.
    It seems to be working so far.
    Gary

Maybe you are looking for

  • JavasScript error Metadata: 509 undefined is not an object

    Hi everybody, When I click on a thumbnail in Bridge 5 , I have a prompt that says "An error occured in Bridge extension. JavasScript error Metadata: 509 undefined is not an object" Thanks for your attention, JP

  • Can I combine 2 forms with different master pages?

    I have two forms that need to be in one PDF together, but have different master pages. The forms are flowed, so the master pages are necessary to keeping the header and footer content in place. Is there any way to combine two forms?

  • Maintain company codes for MM

    The day we assign the plants to the company code, we have to do the settings i.e.,,   in Maintain company codes for MM(T-code : OMSY). 1.What's the siginificane(importance) of this? 2.I have assigned the plants to the company code today,    but forgo

  • Role Priority in VCP

    i want to ask why we use role priority in vcp. do we achive load balancing for access layers switches in below scenario? or  have to configure HSRP or GLPB?

  • Windows 8 Audio has locked up after itunes install?!

    Anyone got a clue how to restore sound operations on a windows 8 system after an itunes install. I uninstalled all apple products, but the audio is still broken. Automated problem resolution didn't work. My last option is to do a restore, but that's