Unix Shell Script -- ORA-00905 error in pl/sql

Below is my unix shell script .... in which i am trying to caluclate difference between time stamps ..... i am getting a severe error when i run --- ORA-00905: missing keyword ( included it bottom of this post )
please look into this and let me know where to correct ....
much appreciated in adv
~~~~~~~~~~~~~~~~~~~~~START of Script~~~~~~~~~~~~~~~~~~~~
#!/bin/ksh
export readTime checkTime timeDiff
# Get initial Time
readTime=`sqlplus -s scott/tiger@database <<EOF
whenever sqlerror exit 1
set escape off
set head off
set verify off
select SYSTIMESTAMP from dual;
EOF
`
echo "readTime value is : $readTime"
# Get end of time
checkTime=`sqlplus -s scott/tiger@database <<EOF
whenever sqlerror exit 1
set escape off
set head off
set verify off
select SYSTIMESTAMP from dual;
EOF
`
echo "value of checkTime : $checkTime"
# calculate time diff
timeDiff=`sqlplus -s scott/tiger@database <<EOF
whenever sqlerror exit 1
set escape off
set head off
set verify off
select CAST(TO_DATE('$time2','''YYYY\/MM\/DD:HH24:MI:SS'''))-CAST(TO_DATE('$VAR1','YYYY-MM-DD:HH24:MI:SS')) from dual;
EOF
`
echo "value of timeDiff : $timeDiff"
~~~~~~~~~~~~~~~~~OUTPUT here ~~~~~~~~~~~~~~~~~~~~~~~
readTime value is :
02-DEC-05 12.07.53.779328 AM -06:00
value of checkTime :
02-DEC-05 12.07.54.013613 AM -06:00
value of timeDiff : 02-DEC-05 12.07.54.013613 AM -06:00','''YYYY\/MM\/DD:HH24:MI:SS'''))-CAST(TO_DATE('
ERROR at line 2:
ORA-00905: missing keyword

You didn't specify if you want a total time for a portion of a shell script, or the whole script in general. If you only want to know the time of the whole shell script, just reference the linux/unix built-in variable ${SECONDS}. This variable is reset for each PID.
I usually add these lines to the bottom of long running shell scripts (just before an exit code):
~~~~~~~~~~~~~~~~~~~~~~~~~
((TIME = ${SECONDS} / 60))
echo "Script ran for ${TIME} minutes. (${SECONDS} seconds total.)
~~~~~~~~~~~~~~~~~~~~~~~~~
Like I said, ${SECONDS} starts ticking from 0 when you start the script, so no need to export the variable, just reference it. The nice part is that you don't have to bother getting into sqlplus and hit the database.

Similar Messages

  • Error while trying to execute a unix shell script from java program

    Hi
    I have written a program to execute a unix shell script in a remote machine. I am using J2ssh libraries to estabilish the session connection with the remote box.The program is successfully able to connect and authenticate with the box.
    The runtime .exec() is been implemented to execute the shell script.I have given below the code snippet.
    try {
         File file_location = new File("/usr/bin/");
         String file_location1 = "/opt/app/Hyperion/scripts/daily";
         String a_mib_name = "test.sh";
         String cmd[] = new String[] {"/usr/bin/bash", file_location1, a_mib_name};
         Runtime rtime = Runtime.getRuntime();
         Process p = rtime.exec(cmd, null, file_location);
    System.out.println( "Connected to the server1" );
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = br.readLine();
    while(line !=null)
    System.out.println(line);
    line = br.readLine();
    br.close();
    p.getErrorStream ().close ();
    p.getOutputStream().close();
    int retVal = p.waitFor();
    System.out.println("wait " + retVal);
    //session.executeCommand("ls");
    catch (IOException ex) {
    I get an error message
    Connected to the server
    java.io.IOException: Cannot run program "/usr/bin/bash" (in directory "\usr\bin"
    ): CreateProcess error=3, The system cannot find the path specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at SftpConnect.main(SftpConnect.java:143)
    Caused by: java.io.IOException: CreateProcess error=3, The system cannot find th
    e path specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    I am sure of the file path where the bash.sh and test.sh are located.
    Am i missing something? Any help would be greatly appreciated.
    Thanks
    Senthil

    Hi, I am using a simple program to connect to a RMI server and execute shell script. I use the Runtime.exec aommand to do the same.
    The script is sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul
    The script when run from the server, gives no errors. But when ran using rthe above method in java, gives errors as follows,
    Mycode:
    String command = "/bin/sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul";
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(command);
    int exitVal = proc.exitValue();
    System.out.println("Process exitValue: " + exitVal);
    java.io.IOException: CreateProcess: /bin/sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul error=3
         at java.lang.ProcessImpl.create(Native Method)
         at java.lang.ProcessImpl.<init>(Unknown Source)
         at java.lang.ProcessImpl.start(Unknown Source)
         at java.lang.ProcessBuilder.start(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at DecryptTest.main(DecryptTest.java:18)
    Can anyone please help

  • Error while executing unix shell script from java program

    Hi All,
    I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
    Code snippet :
    Java Class :
    try{
         String fileName ="test.ksh";
         String argValue ="satish"; // value passed to the script
         String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
         Process proc = Runtime.getRuntime().exec(exeParam);
         int exitValue = proc.waitFor();
         sop("Exit Value  is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    }Test.ksh
      export -- application realated paths..
      nohup  abc.exe 1> test.log 2>&1;
      $1
      exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
    when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
    and able generate the logs properly.
    Pls let us know where exactly i am stuck..
    Thanks in advance,
    Regards,
    Satish

    Hi Sabre,
    As per the guidelines provided by the article, i had done below changes..
    InputStream is = null;
    InputStreamReader iStreamReader = null;
    BufferedReader bReader = null;
    String line = null;
    try{
    String fileName ="test.ksh";
    String argValue ="satish"; // value passed to the script
    String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
    Process proc = Runtime.getRuntime().exec(exeParam);
    is = proc.getErrorStream();
    iStreamReader = new InputStreamReader(is);
    bReader = new BufferedReader(iStreamReader);
    System.out.println("<ERROR>");
    while((line = bReader.readLine()) != null)
    System.out.println("Error is : "+line);
    System.out.println("</ERROR>");
    int exitValue = proc.waitFor();
    sop("Exit Value is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    Now , it's showing something like..
    <ERROR>
    </ERROR>

  • How to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start  and we have to handle the error also

    how to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start  and we have to handle the error also

    032ee1bf-8007-4d76-930e-f77ec0dc7e54 wrote:
    how to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start  and we have to handle the error also
    Please don't overwhelm us with so many details!  
    Just off the top of my head ... as a general approach ... something like
    nohup proca
    nohup procb
    nohup procc
    while (some condition checking that all three procs are still running ... maybe a ps -ef |grep  )
    do
    sleep 2
    done
    procd
    But, we'd really need to know what it is you are really trying to accomplish, instead of your pre-conceived solution.

  • Calling a report from unix shell script

    Hi,
    I had to call a report from unix shell script.
    May i know the procedure to accomplish this
    Thanks in Advance
    A.Gopal

    First you should not include the whole path to your report in the call ...
    Use like this:
    /ora/u01/oracle/v101/as2/bin/rwrun.sh report=an_stati destype=file desname=/ora/u01/oracle/v101/as2/test.pdf desformat=pdf
    In $ORACLE_HOME/bin/reports.sh:
    1) Verify that you have updated the REPORTS_PATH variable to include your folder where you have the report in question
    REPORTS_PATH=/ora/u20/app/qits/env1/run:$ORACLE_HOME/reports/templates:$ORACLE_HOME/reports/samples/demo: ....
    2) Verify that the REPORTS_TMP variable is pointing to a valid location and that the oracle user has access to write on it.
    After that, post the content of the tracefile located at $ORACLE_HOME/reports/logs/{in-process report server name folder}/rwserver.trc
    If no file is present then it means that you need to enable trace in your reports's conf file.... go to the $ORACLE_HOME/reports/conf folder and and locate the .conf file that correspond to your in-process reports server name (as specified in the rwservelet.properties file)... open/edit the file to enable trace logs ..
    i.e.
    Change the following line:
    <!--trace traceOpts="trace_all"/-->
    to <trace traceOpts="trace_all"/>
    Bounce the reports server and try to run the report again, this time the .trc file should be generated, post the content so that we can take a look.

  • Need Help in creating Unix Shell Script for database

    Would be appreciable if some one can help in creating unix shell script for the Oracle DB 10,11g.
    Here is the condition which i want to implement.
    1. Create shell script to create the database with 10GB TB SPACE and 3 groups of redo log file(Each 300MB).
    2. Increase size of redolog file.
    3. Load sample schema.
    4. dump the schema.
    5. Create empty db (Script should check if db already exists and drop it in this case).
    6. Create backup using rman.
    7. restore backup which you have backed up.

    This isn't much of a "code-sharing" site but a "knowledge-sharing" site.  Code posted me may be from a questioner who has a problem / issue / error with his code.   But we don't generally see people writing entire scripts as responses to such questions as yours.  There may be other sites where you can get coding done "for free".
    What you could do is to write some of the code and test it and, if and when it fails / errors, post it for members to make suggestions.
    But the expectation here is for you to write your own code.
    Hemant K Chitale

  • Reg: UNIX shell script at File Adapter

    Hi all,
    I am doing a File to file scenario and using command line arguments in Sending file adapter. I am using UNIX shell script ".sh" file for executing the command.
    I gave the following path at "Run OS command before message processing" parameter:
    /temp/xidelivery/send/FILOSC004_shell.sh
    and this file contains following code:
    <b>#!/user/bin/sh cp /temp/xidelivery/send/FILOSC004_in.txt /temp/xidelivery/send/FILOSC004_input_copy4.txt</b>
    I put the source file, FILOSC004_in.txt and shell script files at the respective paths.
    If I give "cp" command directly in command line it is working fine. But I could not execute this with shell script. Can any body give me the reason where I gone wrong.
    Regards,
    Pavani.

    Hi,
    can you try this,
    bash /temp/xidelivery/send/FILOSC004_shell.sh
    let me know.
    hey you can check the blog below to catch the OS errors,
    /people/michal.krawczyk2/blog/2005/08/17/xi-operation-system-command--error-catching
    Prasad Babu.
    Message was edited by:
            PrasadBabu Koribilli

  • Exit status running java classpath in a unix shell script

    I'm new to putting java into unix scripts. I have a java classpath running inside of a unix shell script. During my testing it will error with java.io.FileNotFoundException error, which I know why that is, but when I set in my unix shell script this to see the right exit status of success/fail, it always shows a 0 for success when that isn't really the case. Below is the two lines I have set to capture the exit status and just display that exit status for now.
    notifycode=$?
    echo $notifycode
    I have these 2 lines above on a line right below my java command in my unix shell script. How can I get my unix shell script to show the right exit status if the java classpath command fails? Thanks for any help.

    That's Java code, it says "End this Java application and send return code 1 back to the shell". As for how the shell gets the return code from the application, that's a question about your shell and not about Java programming, no?

  • Return codes from sqlldr command from unix shell script

    I am trying to capture error code from sql loader from unix shell script and display proper messages.
    sqlldr parfile=sdb.par control=$cntlfile data=$infile bad=$badFile log=$logFile rows=10000
    rows=10000
    retcode=`echo $?`
    case "$retcode" in
    0) echo "SQL*Loader execution successful" ;;
    1) echo "SQL*Loader execution exited with EX_FAIL, see logfile" ;;
    2) echo "SQL*Loader execution exited with EX_WARN, see logfile" ;;
    3) echo "SQL*Loader execution encountered a fatal error" ;;
    *) echo "unknown return code";;
    esac
    Eventhough, there are errors while executing sqlldr, it is always returing recode zero. What could be the possible reason
    Please advice

    Is there a typo in your code ?
    sqlldr parfile=sdb.par control=$cntlfile data=$infile bad=$badFile log=$logFile rows=10000
    rows=10000
    retcode=`echo $?` In this code, you get the return code of the statement in bold which is not the sqlldr statement ...

  • Executing Unix shell scripts with DBMS_SCHEDULER

    I have the following Unix shell script create_backup_file.sh:
    #!/usr/bin/ksh
    /usr/bin/ssh [email protected] /usr/bin/touch/app_home/home/trotestbat/scripts/TRO_batch_complete_`date +%d-%m-%Y-%H%M`
    If I execute this from the command prompt it creates the file on the remote server.
    I've used dbms_scheduler to try and execute this from Oracle:
    BEGIN
    SYS.DBMS_SCHEDULER.CREATE_PROGRAM
    program_name => 'CREATE_TRO_BACKUP_FILE'
    ,program_type => 'EXECUTABLE'
    ,program_action => '/APP/TORPEDO/DTE/SCRIPTS/create_backup_file_tro.sh'
    ,number_of_arguments => 0
    ,enabled => TRUE
    ,comments => NULL
    SYS.DBMS_SCHEDULER.CREATE_JOB
    job_name => 'DTE.TESTAGAIN'
    ,start_date => TO_TIMESTAMP_TZ('2010/05/17 16:09:24.710789 +01:00','yyyy/mm/dd
    hh24:mi:ss.ff tzh:tzm')
    ,repeat_interval => NULL
    ,end_date => NULL
    ,program_name => 'DTE.CREATE_TRO_BACKUP_FILE'
    ,comments => NULL
    END;
    The problem I have is that scheduler executes the shell script and creates the file but it never completes the job. The status of the job is permanently 'RUNNING'. Why is the scheduler not returning a completed status?

    the "infinite" script is usually caused by a prompt (script pauses for a user input).
    Please keep in mind that executing script via scheduler is not the same as manually via prompt.
    1. the script runs as ORACLE user ID (or whatever you specified using DBMS_SCHEDULER.create_credential or/and "$ORACLE_HOME/rdbms/admin/externaljob.ora")
    2. the environment variables are probably not the same.
    My wild guess is that you never ran SSH using "oracle" UID and thus it prompts for permission to add the remote computer’s fingerprint to the user’s ~/.ssh/known_hosts file - since it is a script, it just hangs and waits for input.
    Did you try to login to unix box as oracle uid and run the script manually?

  • Executing java from unix shell script

    Hi, I am trying to execute java program from a unix shell script and the program has a command line parameter. I have tried in ways like
    /opt/java1.4/bin/java CollExtractLoadProcess /home/inbox/archive/file_name
    /opt/java1.4/bin/java CollExtractLoadProcess "/home/inbox/archive/file_name"
    /opt/java1.4/bin/java CollExtractLoadProcess '/home/inbox/archive/file_name'
    /opt/java1.4/bin/java CollExtractLoadProcess file_name
    No matter how I execute it gives me the following error
    Exception in thread "main" java.lang.ClassFormatError: CollExtractLoadProcess (C
    ode segment has wrong length)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
    3)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    Could someone please let me know what is the correct way of doing this?
    Thanks.

    Sounds like you either have a corrupt class file or you're using an older version of the JVM to try to execute classe that were compiled for a newer version.

  • Controlling a procedure execution from a UNIX shell script

    I want to control the execution of a PL/SQL procedure from a UNIX shell script.
    Below, I include the script.
    The control variable which should recive the return of the procedure, dosen't work well.
    I want to control the return, because I wanr to make a UNIX script to control the execution of
    a load data process with some Oracle procedures.
    #!/bin/ksh
    echo "Executing procedure pl/sql"
    SQLPLUS="sqlplus -s /"
    ESQUEMA="esquema1"
    echo "\
    call ${ESQUEMA}.Z_PROC_PRUEBA();" | $SQLPLUS
    echo "Controlling pl/sql execution"
    var_err=$?
    if [ $var_err -gt 0 ]
    then
    echo "Error executing pl/sql"
    else
    echo "pl/sql finished sucessfully"
    fi

    This is not oracle problem. You can try something like this in your shell program ->
    DEV=Udev01/1ods@ODS1
    DEV_ID=`sqlplus -s ${DEV} <<!
             set heading off feedback off verify off
             set serveroutput on
             @/prod/ods/satyaki/prac/ctl_build.sql '$1' '$3';  -- If you sql needs to pass argument
             exit
             !`
    O_DIV_ID=`echo $DIV_ID | tr -s " " | sed 's/^[ ]//g'`
    if [[ $O_DIV_ID -ne 0 ]]; then
          echo "Successfully EXecuted.."
    else
      echo "Failed..."
    fiHope this will help.
    Regards.
    Satyaki De.

  • Java exec() of UNIX shell script

    I have a java application that uses:
    p = Runtime.getRuntime().exec( cmdLine);
    to execute a UNIX shell script, for example:
    #!/bin/ksh
    . /export/pc112477/freeware/work1/wsEnv
    export PATH=/opt/sfw/bin:/usr/ccs/bin:/usr/bin:/usr/ucb:$PATH
    cd /export/pc112477/freeware/work1/usr/src/pkgdefs/SFWnmap
    /usr/ccs/bin/make -e ROOT=$ROOT install
    RESULT=$?
    if [ $RESULT = 0 ]
    then
    echo "Package source"
    cd /export/pc112477/freeware/work1/usr/src/pkgdefs/SFWnmapS
    /usr/ccs/bin/make -e ROOT=$ROOT install
    RESULT=$?
    fi
    exit $RESULT
    Some times the running of the script locks up depending on how much work the script has to, eg. if the make calls pkgmk for a small package it runs okay but if its a large package it locks up in pkgmk.
    The script itself works okay if run directly
    Does anyone have any ideas on why this locks up and how I could stop it doing it.
    Thanks

    For anyone who stumbles across this and needs an answer:
    To empty the standard error and output, you need to use getErrorStream() and getInputStream() on the Process object created when you execed your command. Create new InputStreamReaders with the streams from the process, then wrap those with BufferedReaders and read each line with a while loop. This is the basic thing you need to do:
    try{
    Process proc = Runtime.getRuntime().exec(command);
    InputStreamReader isr = new InputStreamReader(proc.getErrorStream());
    BufferedReader errReader = new BufferedReader(isr);
    String line;
    while((line = errReader.readLine()) != null)
    <do something with each line of error>
    } //end try
    catch(<errors>) {
    <do something with errors>
    } //end catch
    What you really should do is put the stream handling in a separate class that extends Thread, create an instance for the error and output streams, and start each one. There is a class called StreamGobbler that does this sort of thing. Look at http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html to find out more about it and read a detailed explanation of different problems with exec().

  • Can i call unix shell script from B2B callout.

    Hi,
    We had a requirement to invoke a unix shell script from B2B callout implemented class. Here is the code in implementation class:
    public void execute(CalloutContext context,List input,List output)
    throws CalloutDomainException, CalloutSystemException {
    try {
    CalloutMessage cmIn = (CalloutMessage)input.get(0);
    FileOutputStream fos = null;
    String inputFile = "/home/orasoad/digitalsign/input/test.txt";
    String outputFile = "/home/orasoad/digitalsign/output/test.txt.gpg";
    File outFile = new File(inputFile);
    String str =cmIn.getBodyAsString();
    fos = new FileOutputStream(outFile);
    Writer out = new OutputStreamWriter(fos);
    out.write(str);
    out.close();
    String shellFile = "/home/orasoad/digitalsign/dg.sh";
    String cmd[] = new String[] { shellFile, inputFile, outputFile };
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(cmd);
    int i = pr.waitFor();
    BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    StringBuffer sb = new StringBuffer();
    String line;
    while ((line = br.readLine()) != null) {              
    sb.append(line);
    CalloutMessage cmOut = new CalloutMessage(sb.toString());
    output.add(cmOut);
    } catch (Exception e) {
    throw new CalloutDomainException(e);
    We were able to execute the unix shell script from standalone java class with same code. But some how it is not working as expected while invoking the B2B java callout.
    Is it possible to invoke unix shell script from B2B callout?
    Please give inputs.
    Regards,

    Though it's not a good idea to invoke shell scripts from java callout but technically it will work.
    But some how it is not working as expected while invoking the B2B java callout.What is not working as expected? Any error in the log (server-diagnostic.log or server.out)?
    Regards,
    Anuj

  • How can i call a Stored Procedure procedure from Unix shell script

    Hi All,
    I want to call a Strored PL-SQL Procedure through Unix shell script.
    Can any body help me with this.
    Regards,
    Saurabh

    I prefer a seperate script like the other poster mentioned. However, most shells can use a 'here' document as well ...
    sqlplus uid/pwd <<END
    exec myproc
    exit
    ENDRichard

Maybe you are looking for

  • Material Description is not getting updated in IC-WebClient ERP Sales Order

    Hi Experts, The issue is with ERP Sales Order  in IC web client.  Scenerio:1 While creating the Sales order,  If we  enter a product  in Line Item 10 , which is  mapped (Product Type)  in both the systems(CRM&ERP) . It will take the description for t

  • Why to use inheritance when import is sufficient

    The import directive tells the compiler where to look for the class definitions when it comes upon a class that it cannot find in the default java.lang package. After an import statement has been included in our program we can use the methods related

  • Can' t download updates and can't purchase songs on iTunes.  Need a solution.

    Cannot download updates and cannot purchase songs on iTunes.  Tried reloading iTunes.  Did not fix problem.

  • [SOLVED] cannot resolve dependency

    Whenever I try to install gnome I am getting error message - "Cannot resolve dependency " for some files. for example whenever I am trying to install adesklets the error msg is  : [devil@scorp ~]$ yaourt -S adesklets Password: resolving dependencies.

  • About grid control

    can we have a standby database with oracle grid control.i mean i want to have grid control + physical standby for my database(data guard) i just know grid provides data guard facility.kindly explain how does it provide this functionality in grid. if