Output format of sqlplus commands under shell script

hi experts
Can you help with some problems please?
1.) I try to run shell script from dbms_scheduler, which runs sqlplus and the output of sqlplus commands is written to file using command spool. To this point everything is running ok.
My problem is, that output of this file is: (e.g.)
SQL> PROMPT ****************USERB******************
****************USERB******************
SQL> --SELECT sid
SQL> -- FROM v
SQL> -- WHERE audsid = SYS_CONTEXT('userenv','sessionid');
But I don't want the whole first line in the output file. I only want the output of this command, like on the second line.
2.) How Can I write two outputs from sqlplus using command spool running at the same time into one file?
Like in first issue described above. The main sqlplus create a job and this execute the background sqlplus using shell script. But both, the main and the background sqlplus are written to output file at the same time. But only one is written into. But I want the both outputs in the file.
How Can I do that, if I can?
Thanks a lot.

user9357436 wrote:
hi experts
Can you help with some problems please?
1.) I try to run shell script from dbms_scheduler, which runs sqlplus and the output of sqlplus commands is written to file using command spool. To this point everything is running ok. then why are you here?
My problem is, that output of this file is: (e.g.)
SQL> PROMPT ****************USERB******************
****************USERB******************so remove PROMPT line from the file
>
SQL> --SELECT sid
SQL> -- FROM v
SQL> -- WHERE audsid = SYS_CONTEXT('userenv','sessionid');
But I don't want the whole first line in the output file. I only want the output of this command, like on the second line.
2.) How Can I write two outputs from sqlplus using command spool running at the same time into one file?you can not do so.
Like in first issue described above. The main sqlplus create a job and this execute the background sqlplus using shell script. But both, the main and the background sqlplus are written to output file at the same time. But only one is written into. But I want the both outputs in the file.
How Can I do that, if I can?Can't.
Now what?
>
Thanks a lot.Why using DBMS_SCHEDULER to invoke OS script to run sqlplus that runs SQL statements?
this is like making THREE Left Turns, instead of single Right Turn.
Just invoke PL/SQL procedure that does what needs to be done.

Similar Messages

  • Update command in Shell script

    Hi friends
    sqlplus -s / <<END
    set feedback on;
    update tran2 set sno=1;
    exit;
    END
    when i am using update command in shell script like above
    it is updating the database well...but i just want to know how many rows it is updating and i dont want to commit
    for that
    sqlplus -s / <<END
    set feedback on;
    update tran2 set sno=1;
    set feedback off;
    rollback;
    exit;
    END
    It's working fine
    is there any other method to do the same

    Well what's exactly your requirement? The current requirement doesn't make a lot of sense.
    How many row is going to be updated depends on where clause, if you have no where clause that essentially updating whole table, the number of row updated is count of your rows.

  • How to call a HP-UX command or shell script from Forms 4.5

    Does anybody know how to call a unix command or shell script to get a files list of HP-UX server from Oracle Forms 4.5 on client side? I tried to use DBMS_PIPE package to get it done but I failed. Please let me have the solution if anybody knows how. Very urgent!

    I tried the host command before and it just let me shell to the DOS environment but not HP-UX environment as Forms was running on Windows platform. So, I could not run a unix command or a shell script. Is DBMS_PIPE the only way to get it done?

  • Turn commands into shell script

    Hey. I want to do this repetitive task and I'd like to write a shell script to do it. The commands that I want the machine to repeat look like this:
    cd /srv/web-data/conferences
    pwd
    ls -al >> /srv/web-data/work.txt
    cd /srv/web-data/conferences/gurt99
    pwd
    ls -al >> /srv/web-data/conferences/gurt99
    And the machine I'm working on tells me this about itself:
    System = SunOS
    Node = gusun
    Release = 5.8
    KernelID = Generic_108528-10
    Machine = sun4u
    BusType =
    Serial =
    Users =
    OEM# = 0
    Origin# = 1
    NumCPU = 5
    What do I have to do to turn a text file with a list of commands like the above into a shell script?
    Thanks, Rebecca

    Kai,
    Here are 3 function you can use in shell script for executing a statement, sqlfile and procedure
    function execStmt {
      typeset stmt=$4
      echo "
        set feedback off
        set verify off
        set heading off
        set pagesize 0
        whenever sqlerror exit 1
        whenever oserror exit 2
        $stmt;
        commit;
        exit 0
      " |  sqlplus -s  $1/$2@$3
      ret=$?
      if [ $ret -ne 0 ]
       then
          return 1;
       else
          return 0;
       fi
    function execSql {
      typeset sqlfile=$1
      if [ ! -f $sqlfile ]
      then
           echo
           echo "File containing extract count doesn't exist...." 
           echo "Exiting ..."
           echo
           exit 1;
      fi
      echo "
        set feedback off
        set verify off
        set heading off
        set pagesize 0
        whenever sqlerror exit 1
        whenever oserror exit 2
        @$sqlfile;
        exit 0
      " |  sqlplus -s  $2/$3@$4
      retcode=$?
      if [ $retcode -ne 0 ]
      then
           return 1;
      else
           return 0;
      fi
    function execPkg {
       echo "
       set feedback off
       set verify off
       set heading off
       set pagesize 0
       whenever sqlerror exit 1
       whenever oserror exit 2
       exec mypkg.procedure_name($4,$5); -- $4,$5 are argument list
        exit
      " |  sqlplus -s  $1/$2@$3
      ret=$?
      if [ $ret -ne 0 ]
      then
           return 1;
      else
           return 0;
      fi
    }Regards

  • Commands in shell script

    Hai all,
    I need to write a script to add in the cron
         a) exec a procedure
    if successful ,then
         b) Truncate one schema table in the DB
         c) exec a procedure
    Can anyone let me know how to do this ? if anyone have any pointers, for the same , please let me know
    DB : 11.
    Os: Solaris 5.10
    Kai

    Kai,
    Here are 3 function you can use in shell script for executing a statement, sqlfile and procedure
    function execStmt {
      typeset stmt=$4
      echo "
        set feedback off
        set verify off
        set heading off
        set pagesize 0
        whenever sqlerror exit 1
        whenever oserror exit 2
        $stmt;
        commit;
        exit 0
      " |  sqlplus -s  $1/$2@$3
      ret=$?
      if [ $ret -ne 0 ]
       then
          return 1;
       else
          return 0;
       fi
    function execSql {
      typeset sqlfile=$1
      if [ ! -f $sqlfile ]
      then
           echo
           echo "File containing extract count doesn't exist...." 
           echo "Exiting ..."
           echo
           exit 1;
      fi
      echo "
        set feedback off
        set verify off
        set heading off
        set pagesize 0
        whenever sqlerror exit 1
        whenever oserror exit 2
        @$sqlfile;
        exit 0
      " |  sqlplus -s  $2/$3@$4
      retcode=$?
      if [ $retcode -ne 0 ]
      then
           return 1;
      else
           return 0;
      fi
    function execPkg {
       echo "
       set feedback off
       set verify off
       set heading off
       set pagesize 0
       whenever sqlerror exit 1
       whenever oserror exit 2
       exec mypkg.procedure_name($4,$5); -- $4,$5 are argument list
        exit
      " |  sqlplus -s  $1/$2@$3
      ret=$?
      if [ $ret -ne 0 ]
      then
           return 1;
      else
           return 0;
      fi
    }Regards

  • FTP command in shell script

    Hello All,
    I would like to transfer a file from one system to another system.
    so i haven written shell script with ftp command as follows.
    ftp -i 10.14.12.1<< END
    cd C:\Temp
    put $datafile
    ascii
    quit
    But i am getting error.
    Please let me know the sysntax followed by me is correct or thar remote system is down,
    Many thanks,
    Kumar.

    The ftp(1) command is not well-suited for scripting. Instead us the curl(1) tool:
    curl -T myfile ftp://ftp.some.where/down/in/this/dir/
    for example.
    $ man 1 curl
    for more details.

  • 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

  • Stored Proc Execution through OS command using shell script

    Hi All,
    I have a requirement of executing one stored procedure before putting data in Table through JDBC adaptor and two stored procedures after that.
    I was thinking to write a shell script and execute it before and after message processing in adaptor.
    Can anybody please tell me how should i write a shell script for it?
    I have identified that exec <Stored_Proc_Name> is the syntax for it.
    Will i need to write something more in this script?
    Thanks,
    Atul

    Hi Atul,
    Stored procedures are written on the Database server for which you are going to write JDBC adapter.
    you will just call the storedprocedure in to your adapter.
    as per your requirement you shd run one stored procedure (let us say SP1) and then you have to push data into tables and then run SP2 and SP3...
    so for this write three stored procedures and call them into another SP. in this SP you call SP1 first then insert statement to insert data into tables and then SP2 and SP3.
    finally call SP into your JDBC adapter.
    you can call SP1 in SP as below
    Var_SQL :='call SP1 (''' || Var_1 || ''',''' || Var_2 ||''')' ;
    EXECUTE IMMEDIATE Var_SQL;
    i think for this shell script is not required.. correct me if i am wrong...
    Regards,
    Sukarna.

  • Why I have to use -s after sqlplus in a shell script?

    Hi,
    sqlplus -s "/as sysdba" is in my script. But why I have to use -s?

    Hi
    Run sqlplus /? from your command line and you see that option means silent mode, i.e. suppression of SQL*Plus banner, echo's and prompts.
    Bye Auke
    Message was edited by:
    aukequist

  • SQLPLUS @ command should open script file with a WRITE lock

    I know that this might be considered petty; but there are at least two reasons why it would be nice if the @command files were locked while processing.
    (1) It is currently possible to edit the file while it is processing. Sqlplus reads the file line by line; so the same line might be read more than once, or lines might be lost depending on whether the editor added or removed lines. I seem to fall into this error when I am busy, launch a long running script and then, 10 minutes later, think of a change I want to make and start editing the file. In any event, it seems logical to me that SQLPLUS might legitimately require that once an @ command file has started processing that it be locked for changes while processing.
    (2) While it is all well and good just to say that I shouldn't do that, the number of times in the last 25 years that I have put spool file.sql instead of spool file.log in a command file called file.sql beggers the imagination. Sometimes my fingers just type faster than my brain. The result of this typo is that in combination with (1), file.sql is overwritten and terminates having done nothing except replace itself with an empty file.
    I know that these problems could easily be avoided if I was perfect; but I've been doing this long enough to know that I'm not and never going to be.
    So just my 2 cents worth as a suggestion.
    Thank you, Mark
    Edited by: mmillman on Dec 3, 2009 2:17 PM

    If you ever find this answer, it would be extremely useful to me right now.

  • Airport Command Line / Shell Script Tool

    Hi,
    Is there a way to issue a command to cause an Airport Extreme to reboot? I need to restart my airport extreme fairly often.
    Thanks,
    Bruce

    Hi,
    try OMBPlus.
    #Connect to repository:
    OMBCONNECT owbrep/passwd@mydesignhost:1521:mydesignrep USE REPOSITORY 'owbrep'
    #Export
    OMBEXPORT MDL_FILE 'C:\\file.mdl' FROM PROJECT 'MY_PROJECT' WITH DEPENDEE_DEPTH MAX INCLUDE_USER_DEFINITIONS OUTPUT LOG 'C:\\file.log'
    OMBDISCONNECT
    This export one project. If you want to export all projects, don't forget the project "PUBLIC_PROJECT", that contains all public stuff.
    Put this into a script and here you go.
    Checkout the OWB API and Scipting Guide for more options on OMBEXPORT.
    Regards,
    Carsten.

  • 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

  • Can we not run 2 sqlplus programs in a shell script ?

    Hi
    I have 2 spool programs which need to be called from a shell script .
    When i try to do it , only the first spool program runs but not the second one . Is their any reason ?
    #!/usr/bin/bash
    ORACLE_HOME=/oracle10g/product/10.2.0/client_1
    export ORACLE_HOME
    sqlplus -s abcdata/daddy@DevOra < lit_fac.sh > output.log 2>&1
    sqlplus -s abcdata/daddy@DevOra < lit_fac_cat.sh . output_cat.log 2>&1
    exit
    How to run 2 scripts containing select queries each from sqlplus in another shell script ?
    Thanks in advance ..

    user8703472 wrote:
    Hi
    I have 2 spool programs which need to be called from a shell script .
    When i try to do it , only the first spool program runs but not the second one . Is their any reason ?
    #!/usr/bin/bash
    ORACLE_HOME=/oracle10g/product/10.2.0/client_1
    export ORACLE_HOME
    sqlplus -s abcdata/daddy@DevOra < lit_fac.sh > output.log 2>&1
    sqlplus -s abcdata/daddy@DevOra < lit_fac_cat.sh . output_cat.log 2>&1
    exit
    How to run 2 scripts containing select queries each from sqlplus in another shell script ?
    Thanks in advance ..As I said before .. the term "spool program" has no meaning in Oracle and only serves to cloud the issue. I know you are used to using this term with other products, but "When in Rome ...."
    As for your example above, why are you using what appears to be a unix shell script as redirected input into sqlplus? And in the second line, what's with the dot (".") between "lit_fac_cat.sh" and "output_cat.log"?
    If these .sh files are really sql files (which is the only thing sqlplus know how to process) then the proper things to do are
    1) name them lit_fac.sql and lit_fac_cat.sql
    2) feed them to sqlplus in the standard, documented manner:
    sqlplus -s abcdata/daddy@DevOra @lit_fac.sql

  • 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

  • Automator/Applescript not running shell script properly

    I can open Terminal, and this command works:
    lame -h --abr 256 /Users/myhome/Desktop/Some\ Wav\ File.wav /Users/myhome/Desktop/TheMP3.mp3
    But when I try to run the same command in applescript from Automator, it fails.
    set sourceFile to quoted form of POSIX path of "/Users/myhome/Desktop/Some Wav File.wav"
    set mp3File to quoted form of POSIX path of "/Users/myhome/Desktop/TheMP3.mp3"
    set command to "lame -h --abr 256 " & sourceFile & " " & mp3File
    display dialog command
    do shell script command
    The display dialog outputs:
    lame -h --abr 256 '/Users/myhome/Desktop/Some Wav File.wav' '/Users/myhome/Desktop/TheMP3.mp3'
    Which, as little as I know of applescript, is how applescript handles spaces in filesnames. Can anyone please help?

    You need *do shell script* attribute described in the 10.4 Changes section of http://developer.apple.com/mac/library/releasenotes/AppleScript/RN-AppleScript/R N-104/RN-10_4.html#//appleref/doc/uid/TP40000982-CH104-SW1 Additional info can be gained by posting to the AppleScript and Unix forums under OS X Technologies.

Maybe you are looking for

  • ITunes 7.7 errors in Vista 64-bit are drivin me crazy.

    Alright, I'll break down and ask for help. For the past month, my iTunes has been unable to sync with my phone. I'll try to detail the problem as much as I can. I upgraded my iTunes from 7.6 to 7.7, and after, my iPhone wouldn't sync, saying "This iP

  • How can I compare the actual and expected values in Unit testing when they are XML files?

    I have created a unit test for a method in VS 2008. My expected value and actual value are XMLs. Therefore though the output is same as I expect it gives an error as I am doing string comparison now. How can I compare these 2 XMLs in expected output

  • File Server vs. Time Capsule Device

    I have an old mac mini I'm thinking of using as a network file server for time machine backups.  Other than the "wireless base station feature" of the Time Capsule device, are there any other features of the Time Capsule I'll miss out on by going fil

  • Lost my library - except purchases!?

    Downloaded new iTunes last night, hooked iPhone up to transfer purchases but now only the purchases are showing - where's the rest of the library? I still have all my content on iPod and iPad but am terrified to hook them up to my pc in case the same

  • Using jasper Report.

    I want to export one String[] (array )to CSV or XLS file using Jasper reports. I have installed Jasper Reports in my eclipse IDE. Can anyone help me regarding this. regards raj