Executing a shell script from pl/sql stored procedure

Hi,
I have Oracle 8i on HP-UX.
I am passing a shell script name as a parameter to a user defined function from a pl/sql stored procedure. This user defined function has insterface to a user defined Java class file in Aurora java virtual machine which is written using runtime class which can execute any OS command or any shell script. I am getting any OS command run successfully, but could not run my own shell script. It's is not getting environment variables of my own, so not getting executed. So please suggest how can get these env variables in my shell script and also suggest other sucurity concerns to be taken into consideration.
If you have any questions please let me know.
This is really a very urgent issue.....
Please help me.
Thanks
Srinivasa Rao Kolla

Your best bet is to use the dbms_pipe builtin package to send the command to the host

Similar Messages

  • Call a UNIX shell script from an oracle stored procedure

    We need to call a UNIX shell script from an oracle stored procedure
    i.e. the control should come back to the procedure once the script completes. Can any body help to achieve this ?

    There are various ways in achieving this.
    For Example, you can call a PRO*C-Library residing on the database server.
    This requires a PL/SQL library to be generated and some changes to the Listener configuration.
    It is also possible to implement a java procedure on the database being invoked by a PL/SQL wrapper class.
    In this way (and if used right) there is also granularity regarding the filestructure permissions given and it may be called during a Forms or other PL/SQL session.
    The article below explains a more generic approach how to invoke shell commands from within an Oracle Instance.
    Be careful with this, because it really works ;)
    Refer to :
    http://www.oracle-base.com/articles/8i/ShellCommandsFromPLSQL.php
    Message was edited by:
    user434854

  • How to pass arguments to a Unix shell script from PL/SQL?

    We want to run a Linux shell script from PL/SQL (10g). This is our code to run the script only and it works fine.
    dbms_scheduler.create_job
              job_name=>'RUN_LINUX_SCRIPT_' || v_job_name,
              job_type=>'EXECUTABLE',
              job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check.sh',
              enabled=>TRUE,
              auto_drop=>FALSE
            );Now we have a requirement to pass 2 arguments to the .sh file. In the .sh file the 2 arguments are defined as $1 and $2.
    I used this method.
    dbms_scheduler.create_job
              job_name=>'RUN_LINUX_SCRIPT_' || v_job_name,
              job_type=>'EXECUTABLE',
              job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh',
              --job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh /vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt /vol0/FileLoadDir/Bank/DATA_FILES/abcdefghij.txt',
              --job_action=>'#!/bin/bash spell /vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt > /vol0/FileLoadDir/Bank/DATA_FILES/abcde.txt',
              number_of_arguments => 2,
              enabled=>FALSE,
              auto_drop=>FALSE,
              comments => 'Testing by Channa'
          DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE (
            job_name                => 'RUN_LINUX_SCRIPT_' || v_job_name,
            argument_position           => 1,
            argument_value          => '/vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt');
          DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE (
            job_name                => 'RUN_LINUX_SCRIPT_' || v_job_name,
            argument_position       => 2,
            argument_value          => '/vol0/FileLoadDir/Bank/DATA_FILES/abcdefghij.txt');
          DBMS_SCHEDULER.enable (name => 'RUN_LINUX_SCRIPT_' || v_job_name);But I get an error saying:
    STANDARD_ERROR="/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh: line 4: read: `/vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt': not a valid identifier
    /vol0/FileLoadDir/Bank/DATA_FILES/spell_check2"

    Check this post:
    pass parameter from PL/SQL to Unix "as is"

  • Call Shell Script from PL-SQL

    Hello All,
    I have been using some well known Java Class and Procedures to execute shell scripts from PL-SQL.
    The different environments I was using before were
    1)
    Operating System (Server) AIX version 5
    Oerating System(Client) Microsoft Windows XP Service Pack 2
    Oracle Database Version Oracle Database 10g Enterprise Edition Release
    10.2.0.1.0
    2)
    Operating System (Server) Red Hat Linux 3.4.5-2
    Oerating System(Client) Microsoft Windows XP Service Pack 2
    Oracle Database Version Oracle Database 10g Enterprise Edition Release
    10.2.0.1.0
    But suddenly I had to drop and recreate the Databases on 1st (AIX) environment
    and
    reinstall the Operating System (Server) Red Hat 3.4.5-2 on IInd environment stated above (which obviously means the reinstallation of Oracle Database there!)
    Now the shell script(through PL-SQL)is executing smoothly for the IInd (Linux) environment[b] but not executing for the Ist (AIX) environment
    and I am not getting how to solve the problem.
    I have given all the permissions to users, shell scripts and all as they were before.
    Can you please help?
    Regards,
    Abhijit.

    Hello All,
    I have been using some well known Java Class and Procedures to execute shell scripts from PL-SQL.
    The different environments I was using before were
    1)
    Operating System (Server) AIX version 5
    Oerating System(Client) Microsoft Windows XP Service Pack 2
    Oracle Database Version Oracle Database 10g Enterprise Edition Release
    10.2.0.1.0
    2)
    Operating System (Server) Red Hat Linux 3.4.5-2
    Oerating System(Client) Microsoft Windows XP Service Pack 2
    Oracle Database Version Oracle Database 10g Enterprise Edition Release
    10.2.0.1.0
    But suddenly I had to drop and recreate the Databases on 1st (AIX) environment
    and
    reinstall the Operating System (Server) Red Hat 3.4.5-2 on IInd environment stated above (which obviously means the reinstallation of Oracle Database there!)
    Now the shell script(through PL-SQL)is executing smoothly for the IInd (Linux) environment[b] but not executing for the Ist (AIX) environment
    and I am not getting how to solve the problem.
    I have given all the permissions to users, shell scripts and all as they were before.
    Can you please help?
    Regards,
    Abhijit.

  • Can any one tell me how can i call a shell script from pl/sql

    i like to call shell script from pl/sql procedure.
    can any one suggest how can i do this

    Have you not mastered in asking the same kind of question ?
    First do write a script...
    no one will spoon feed you.
    How can i call a shell script from procedure
    How to call Shell Script from pl/sql block
    -Sk

  • Executing a shell script from a Trigger

    All,
    I have to write a script to do the following requirement.
    There is a file called BUSINESS_DATE.TXT.
    This file get updated once the oracle partition created. In Oracle, Partition will be created every day. There is a seperate script scheduled to take care ORACLE partition creation.
    The above file will have only one row. i.e
    03092012
    If Oracle partition creation job failed, the above file won't be updated.
    My requirement is,
    I have to check whether the BUSINESS_DATE file is updated today or not. If yes, I will have to move the files from common area to input file directory to process those files.
    All file name will amend with current date.
    i.e
    LIDDIFD03092012.TXT
    The key part is to check the BUSINESS_DATE.TXT file is updated properly or not.
    We don't know what time the file will get updated. So we are planning to schedule the new script to run for every 15 mins to check whether the file is updated or not
    But...I just thougt instead of writing a shell script to do the above one, Why shouldn't I capture the date in a table (New table needs to be created) and use ORACLE TRIGGER to run the shell script to move the files from common area to input file directory to process those files?
    My Proposal in ORACLE :
    Create table business_date
    rep_date varchar(15),
    curr_timestamp timestamp
    Once the oracle partition created , one row will be inserted into the above table. This adjustment needs to be implemented partition script.
    Once this table get record, TRIGGER should call SHELL SCRIPT to move the files from common area to input area.
    If I implement ORACLE TRIGGER, The script which will check whether the file got updated or not for 15 mins is not required. Right? Inputs from experts are welcome!

    >
    But...I just thougt instead of writing a shell script to do the above one, Why shouldn't I capture the date in a table (New table needs to be created) and use ORACLE TRIGGER to run the shell script to move the files from common area to input file directory to process those files?
    >
    Triggers should not be used to do transactional work. There is no COMMIT in a trigger. What happens if the trigger runs the shell script and then a ROLLBACK occurs? You will have run the shell script when it shouldn't run.
    Create a stored procedure to run the shell script. Call the stored procedure when the partition is created.
    If you were using 11g and interval paritioning you wouldn't need to create the partitions manually. Oracle could create the partitions automatically.

  • Executing a shell script from a java program

    Hi,
    I'm facing a problem while executing a shell script from a jsp page.
    I'm using exec() function.
    It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
    Will u please help me in this.
    If there is any other ways to execute a shell script from a jsp page other than Runtime.exec().If so let me know.
    Thanks in advance.

    I think this shud workMaybe - but it is wrong! Why do you create aReader
    and then read bytes which are turned into a String
    without worrying about whether or not the bytes area
    String and without worrying about the character
    encoding if the bytes do represent characters and
    without worrying about how many bytes wereactually
    read.
    Also, both you and the OP should read, digest and
    follow the advice given in
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-
    traps.htmlI dont care if it is wrong. This code works for me.
    We are here to solve problems not to find which post
    is wrong.It is wrong! You are posting bad advice that is very wrong! It may work for you but it is wrong in general! WRONG WRONG WRONG.
    If you have a solution then post it I did post a solution! The reference I gave will explain to you and the OP exactly how it should be done.
    rather then
    posting rude comments.I was not rude! I was explaining just some of what was wrong!

  • Executing a shell script from a jsp page

    Hi,
    I'm facing a problem while executing a shell script from a jsp page.
    I'm using Runtime.exec() function.
    It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
    Will u please help me in this.
    If there is any other ways to execute a shell script from a jsp page other than Runtime.exec() like RMI etc,.If so let me know.
    Thanks in advance.

    Hello,
    It's hard to help you but what you can do is listening to the outputs of your script, you should read the output stream and error stream and send them to the default console.
    Check this excellent article : http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
    Best regards,
    Olivier.

  • 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 execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • Execute a shell script from inside PL procedure

    Oracle 9205 on Red Hat Enterprise Linux 3.
    Is there any way to execute an O.S. shell script from inside a PL/SQL procedure?
    This is, that PL_SQL procedure evaluate a situation and if the condition is true, it calls and execute an O.S. shell script.

    PL/SQL procedures do not support any native calls to the OS; however, you can code calls to external procedures or JAVA procedures to perform tasks on the OS.
    Prior to these two methods any of the following packages dbms_alert, dbms_pipe, or utl_file could be combined with a daemon type program to issue OS commands, run shell scripts, etc....
    There is a writeup on metalink with examples.
    HTH -- Mark D Powell --

  • Calling Unix shell script from PL/sql code

    Hi
    I need to call a shell script from a procdeure which i need to run in toad. Let me kno whow can i do that and connect to unix box with an example.

    Thanks Avinash,
    That on was very useful.
    When I try to execute I got the following error.
    Could you let me now What privileges are required?
    SQL> BEGIN
    dbms_scheduler.create_job(job_name => 'myjob',
    job_type => 'executable',
    job_action => '/home/rananto/a.sh',
    enabled => TRUE,
    auto_drop => TRUE);
    END;
    / 2 3 4 5 6 7 8
    BEGIN
    ERROR at line 1:
    ORA-27486: insufficient privileges
    ORA-06512: at "SYS.DBMS_ISCHED", line 99
    ORA-06512: at "SYS.DBMS_SCHEDULER", line 262
    ORA-06512: at line 2
    SQL> exec dbms_scheduler.run_job('myjob');
    BEGIN dbms_scheduler.run_job('myjob'); END;
    ERROR at line 1:
    ORA-27475: "CRDM.MYJOB" must be a job
    ORA-06512: at "SYS.DBMS_ISCHED", line 150
    ORA-06512: at "SYS.DBMS_SCHEDULER", line 441
    ORA-06512: at line 1

  • Executing a shell script from a form (client / server)

    From a form in a client server environment, I would like to execute a shell script on the server.
    Environment:
    Server: SunOS 5.6
    DB : 8.0.5
    Forms : Developer 6 w/patch 6A
    Forms - 6.0.5.34.0

    Jim,
    Yes. Use the host command from forms and call the command rexec.
    Raymond
    null

  • Example: Executing a shell script from java

    Hi. There are many other posts in the forums related to executing a unix script from java, but I wanted to post another example that I thought might be helpful...
    The key thing to executing the script is to include the -c switch for the sh command. This tells the sh command that you are passing a string to be interpreted as input. Without this switch, the script does not execute as you'd expect it to. Also, use a string array to pass each part of the sh command.
    Here is a working sample class, along with a test script to execute it:
    public class TestShellScript {
    public static void main(String[] args)
    String[] chmod = {"chmod","777","testscript1"};
    String[] runscript = {"sh","-c","./testscript1 > jdata.out"};
    Runtime rtime = Runtime.getRuntime();
    try
    rtime.exec(chmod); // Set the authorities for testing
    rtime.exec(runscript); // Run the script with redirection
    catch (IOException e)
    e.printStackTrace();
    rtime = null;
    Here is a test script to wrap the java call:
    #!/bin/sh
    cd /<your script dir>
    export -s CLASSPATH=/<your jar dir>/TestShellScript.jar
    export -s PATH=/<your script dir>:/usr/bin
    java TestShellScript
    - Hope this helps.

    I don't know exactly but the code written below is working fine try the same with your code .Even with your code instead running the code with
    " ./<filename> ",if you execute it with "sh <filename>" command without changing the mode of the file it is executing properly.
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
    public ScriptBuilder()
    public void writeScript() throws java.io.IOException
    FileWriter writer = new FileWriter(new File("test_script"));
    writer.write("#! /bin/sh\n");
    writer.write("ll>/home/faiyaz/javaprac/checkll");
    writer.flush();
    writer.close();
    Runtime rt= Runtime.getRuntime();
    rt.exec("chmod 777 test_script");
    rt.exec("./test_script");
    } public static void main (String[] args)throws java.io.IOException
    ScriptBuilder sb = new ScriptBuilder();
    sb.writeScript();
    }

  • APEX - accepting OUT variable values from PL/SQL Stored Procedure

    I have created a page (Form) which is accepting values text fields.
    In the Page Processing section under Processing, I am passing the values to a PL/SQL Stored Procedure, which acts like an API. The procedure contains code to validate the entered data and finally insert the data into the base tables. The procedure also contains OUT variables in the parameter that would return status of processing and any error messages.
    Now, my question is, how can I make the page accept these OUT variables from the procedure. What I wish to do is, to capture these messages/processing status from the procedure in the page. For example, if there is a error in the data and the procedure is sending this message in the OUT variable, I need this to be displayed on the page as an error message.
    Is this possible in APEX?
    Regards,
    Santhosh Jose

    Hi VC,
    I just tried putting the string directly instead of the variable. Its still not giving me the expected results.
    HOWEVER, I think the reason was because of the EXCEPTION block in my code. I have an EXCEPTION block to handle exceptions. I commented the WHEN OTHERS section and now the error message is coming on the page.
    So what I have done now is as follows: At the point at which the error is expected, I am raising a handled exception. And within the exception handling, I am giving RAISE_APPLICATION_ERROR.
    WHEN ex_main_error*
    THEN*
    p_status := 2;*
    p_msg := 'ERROR Stage: '||lc_err_stage||' ERROR Message: '||lc_err_msg;*
    RAISE_APPLICATION_ERROR (-20001, p_msg);*
    This is working now! Which is very good news. Thanks once again for your help!
    Regards,
    Santhosh Jose

Maybe you are looking for

  • Computer really slow, ran a diagnosis, here are the results

    Hi, My computer was really slow so i removed some of the lauch/deamon that i could fnd and ran a diagnosis, What else is wrong, what should i do? here are the results: Start time: 01:27:56 02/19/15 Model Identifier: MacBookPro8,1 System Version: OS X

  • Won't open in camera raw

    I've just installed my cs6 to my laptop, why wont it open raw files ? , when I installed on my main computer it works fine

  • How do I accept or decline a calendar invitation in iOS8 without sending a response?

    This specific scenario is Exchange 2013 and iOS8. I want to be able to accept/decline/tentative in response to a calendar invitation from my iPhone without sending a response to the inviter. I do not think Exchange probably has anything to do with it

  • I have problem with my Itunes.

    Когда я нажимаю на сообщить о проблеме меня перекидывает вот сюда что делать?

  • SRP541W WAN Load Balancing and NAT

    Hello All, New to the forums. Thanks for taking the time to read my post. I recently switched my office over from a RV042 to SRP541W. We have 2 DSL lines and have used the Load Balance feature on the RV42 to make the best of the connecton speeds. Whe