DBAsupport.com Forums - Powered by vBulletin
Results 1 to 8 of 8

Thread: Is it possible to call a shell script from a procedure

  1. #1
    Join Date
    Feb 2001
    Posts
    44
    HI All,
    I have to design a procedure which has to run a shell script aftre completing some activity.Is it possible to create such a procedure?
    Thanks in Advance

  2. #2
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    I dont know and I dont think so :(

  3. #3
    Join Date
    Mar 2001
    Location
    Ireland/Dublin
    Posts
    688
    If you know how to execute shell script from C++ function, you will be able to execute it from Oracle function.
    I think you have to write C++ external function which makes it for you.

  4. #4
    Join Date
    Mar 2001
    Location
    Ireland/Dublin
    Posts
    688
    Little sample:

    if you create file tmp.c

    main()
    {
    int status;
    if (fork() == 0)
    execl("/bin/date","date",0);
    wait(&status);
    }

    then compile it: make tmp

    oracle@mci:~/temp > ./tmp
    Thu Jun 21 12:25:44 BST 2001

    You will get date time. Approximatly the same you may do in your case just call 'sh script_name'.

    Best wishes!

  5. #5
    Join Date
    Dec 1999
    Location
    Alpharetta, GA, US
    Posts
    192
    I dont think you can execute the Shell from the C or C++ executible. If you want to do this seach for the this
    "Calling External Procedure".

    Good Luck
    Chan
    OCP7.3/8.0/8i/9i
    Sun Certified Sys. Admin

  6. #6
    Join Date
    Jan 2001
    Posts
    2,828
    Hi

    you can definately run programmes written in java c and c++ in oracle 8i.but you cant run a say korn shell script.could you tell me your exact requirements.you can also refer oracle pl/sql adavnced programming for this.but i dont think so executing a shell script is possible.

    regards
    hrishy

  7. #7
    Use java. We do this to call external shell scripts from within a package.

    follow the JDBC examples found in the docs.

    Create a java stored procedure with similar patterns as the sql strored proc.

    this is how I did it... BTW, you need the JVM installed ($ORACLE_HOME/javavm/install/initjvm.sql) have 50M of shared_pool at least when youinstall it (as sys). Again, read the docs on this.

    HAve your own procedure call the java proc: example:

    create or replace package body java_integration as

    procedure integrate (business_id in varchar2, file_name in varchar2) is
    language java name
    'java_integration.integrate(java.lang.String, java.lang.String)';

    end java_integration;
    /

    You can do with a proc, and not a pkg, but I prefer packages.

    In my other code, simple SQL I call this one:
    java_integration.integrate(V_business_id, V_file_name);

    This call the above java proc, which then calls the java_integration program, of the same name..

    in the code I have something like this: I pass in the arguments and the path of the executable (which I hard code in my case), and execute it.


    java_integration.java:

    public class java_integration
    {
    public static void main (String args [])
    {
    public static void integrate (String biz_id, String file_name)
    {
    try {
    int exitValue;
    Process proc;
    String exec_stmt = "/integrate_external/RTNYC/integrate.sh";
    exec_stmt += " " + biz_id + " " + file_name;
    System.out.println(exec_stmt);
    proc = Runtime.getRuntime().exec(exec_stmt);
    proc.waitFor();
    exitValue = proc.exitValue();
    System.out.println("Exit condition: "+exitValue);
    }
    catch (Exception e)
    {
    System.out.println("failure in callnow");
    System.out.println(e.getMessage());
    }
    }
    }


    This and the other procedure must be loaded and compiled:

    loadjava -u DB_USER/DB_PASS@CONN_STR -resolve java_integration.class

    then sqlplus USER/PWD
    @java_integration.sql (contains the package above)

    that's mostly it. good luck.




  8. #8
    Join Date
    Mar 2001
    Location
    Ireland/Dublin
    Posts
    688

    THERE IS NOTHING IMPOSIBLE !!!

    O'k !
    Little lesson for those guys who don't know C++ & Unix & Shell together:
    step 1:
    create file called : hello.sh
    hello.sh:
    mkdir /home/oracle/temp/hello
    step 2:
    create C++ programm: temp.c
    temp.c:
    #include
    main()
    {
    if (fork() == 0)
    execl("/bin/sh","/home/oracle/temp/hello.sh","hello.sh", NULL);
    }
    step 4:
    make temp
    step 5:
    ./temp
    step 6:
    check new directory. :-)

    THERE IS NOTHING IMPOSIBLE !!!
    QUESTION IS HOW TO CAN I DO IT ?

    Best wishes!


    Originally posted by Chandra
    I dont think you can execute the Shell from the C or C++ executible. If you want to do this seach for the this
    "Calling External Procedure".
    Good Luck
    [Edited by kgb on 09-07-2001 at 10:30 AM]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width