Excute Unix command Using PL SQL

Greeting,
how can I execute shell unix commands from PL SQL and without passing by the Java virtual machine, because my database server is not very performant to support the heaviness of Java.
Thank you for ur help!!!

Is this what you need ?
TEST@db102 SQL> create table test(dir varchar2(100), url varchar2(200));
Table created.
TEST@db102 SQL> insert into test values('/tmp','http://otn.oracle.com');
1 row created.
TEST@db102 SQL> commit;
Commit complete.
TEST@db102 SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[ora102 work db102]$ cat /tmp/wget.sh
#!/bin/bash
rm -f /tmp/index.html
/usr/bin/wget -P $1 $2
[ora102 work db102]$ sqlplus test/test
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jul 29 17:11:28 2006
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
TEST@db102 SQL> DECLARE
  2     v_dir   varchar2(100);
  3     v_url   varchar2(200);
  4  BEGIN
  5     select dir, url into v_dir, v_url
  6     from test;
  7     DBMS_SCHEDULER.CREATE_JOB(
  8     job_name=>'testjob',
  9     job_type=>'EXECUTABLE',
10     job_action=>'/tmp/wget.sh',
11     number_of_arguments => 2,
12     enabled => FALSE);
13     dbms_scheduler.set_job_argument_value('testjob',1,v_dir);
14     dbms_scheduler.set_job_argument_value('testjob',2,v_url);
15     dbms_scheduler.enable('testjob');
16* end;
TEST@db102 SQL> /
PL/SQL procedure successfully completed.
TEST@db102 SQL>sorry for lost indentations, but tags do not help us these days....

Similar Messages

  • Operating system Cammand such as UNIX command using PL/SQL

    Hi All,
    I am using forms 4.5 using oracle financials 10.7 and I want to execute an operating system file such as move on server side. I am able to do it on client side using host command but cannot figure out how I can use it on server side. I am using following version of oracle:
    Oracle8i Enterprise Edition Release 8.1.7.3.0 - 64bit Production
    PL/SQL Release 8.1.7.3.0 - Production
    CORE 8.1.7.0.0 Production
    TNS for HPUX: Version 8.1.7.3.0 - Production
    NLSRTL Version 3.4.1.0.0 - Production
    Thanks
    Aqil

    If I dont have java support is there no way to solove this problem?Steven Feuerstein provides some simple example here
    http://apex.oracle.com/pls/otn/f?p=2853:4:12114297745467903505::NO::P4_QA_ID:3202

  • Unix command using in pl/sql

    Hi all,
    Can we use unix command in pl/sql statement..
    Regards,
    Manikandan.k

    Hi Manikandan,
    You cantry this via Oracle Database Jobs. You can create a Job that uses your Shell Script & then execute the job in a procedure / function. It's one of the ways to access the underlying Operating System via PL/SQL.
    Regards,
    Sandeep

  • Unable to excute unix command from java program

    import java.io.File; // is java code
    public class RunSystemCommand {
    public static void main(String args[]) {
    String s = null;
    // system command to run
    String cmd = "ls ";
    // set the working directory for the OS command processor
    File workDir = new File("c:/cygwin/cygwin");
    Process p = Runtime.getRuntime().exec(cmd, null, workDir);
    p.waitFor();
    I am tryiing to excute above code to run unix command on cygwin but gave folllowing error...... but works well to open a note pad..
    Exception in thread "main" java.io.IOException: CreateProcess: C:/cygwin/bin err
    or=5
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Unknown Source)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at d.main(d.java:19)
    It seems using this functionone cannot excute unix commands..please help to do so..

    Are you sure you want cygwin/cygwin?
    the following works fine for me, you may need change the workDir to your bin folder
    import java.io.File; // is java code
    import java.io.InputStream;
    public class RunSystemCommand {
        public static void main(String args[]) throws Throwable {
         String s = null;
         // system command to run
         String cmd = "ls ";
         // set the working directory for the OS command processor
         File workDir = new File("c:/cygwin/bin");
         Process p = Runtime.getRuntime().exec(cmd, null, workDir);
         InputStream pis = p.getInputStream();
         while( pis.read() != -1 ); // added, as otherwise the ls hangs.
         p.waitFor();
    }

  • Run a shell command using Pl/Sql

    hi all
    i wonder if anyone knows a way to run a shell command using pl/sql
    other than java stored procedure
    as it seems not to be working in my case
    thanx in advance,
    Rasha

    ofcourse not
    i sent it once then i've got disconnected from interent then i reconnected
    and resend my question so it was sent twice
    now i hope you can answer my question !!!
    Do you really think when asking twice or more often you will get a quicker answer?

  • Execute unix command using java

    Hello
    Can we execute a unix command using java? If it is how we can execute. Is this affect the performance of the program.
    Thanks

    I tried what you said. But its not working and returning error message,
    java.io.IOException: CreateProcess: ls -a error=2
         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)
    If i try this statement,
    Runtime.getRuntime().exec("c\windows\notepad");
    It is working fine.
    Any idea about this.
    Plz ...........

  • Running unix command using java shows error

    Hi All,
    I am trying to run UNIX move command using Java exec method but its throwing error, unable to rename. Here below is the code i am trying to run to move all files from one directory to another directory. source and destination directory exists.
    public class Demo
        public static void main(String args[])
            try
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec("mv /home/demo1/* /home/demo2");
                int exitVal = proc.waitFor();
                System.out.println("Process exitValue: " + exitVal);
            } catch (Throwable t)
                t.printStackTrace();
    }if i give "mv /home/demo1 /home/demo2" in exec method, its working, with * character its giving problem.
    Please help me in resolving the problem.
    Thank you

    Characters like *, >, &, |, etc. are interpreted by the command shell--that is by the bash, zsh, etc. programs. When you execute a command with ProcessBuilder or Runtime.exec, you're not going through one of those shells, so their interpretation of those characters is not available.
    In your code, the character * is being delivered directly to the mv command (which doesn't think * is anything special), as opposed to being turned into a list of files and directories as it would be when it's interpreted by the shell. The mv command doesn't know anything about the * character being special.
    If you want to have those shell interpretations, you need to execute the command through a shell. One example is like so, but a) you'll want to read up on the methods in exec() that take arrays of String, and b) you'll want to read up on ProcessBuilder, and c) you'll need to check your shell's man pages to see the exact syntax and arguments.
    runtime.exec("/bin/bash -c 'mv x/* y'");

  • Calling UNIX command from PL/SQL Procedure

    Is there a way to call a UNIX command (exa. ls) from within a PL/SQL stored procedure? Looking through the various packages, I didn't see anything that would give me this ability.
    I also looked through all the previous questions and nothing looked encouraging.
    Thanks in advance,
    Russ

    Russ,
    I thought I'd read a similar question awhile ago and did a search on the word host in this forum and found the following from July 9th that might help you:
    http://technet.oracle.com:89/ubb/Forum88/HTML/001611.html
    In that post I think the link listed by Barbara Boehmer in has changed to:
    ]http://asktom.oracle.com/pls/ask/f?p=4950:8:24579::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:16212348050,{host}
    It looks like they give solutions for Oracle 7, 8 and 8i.
    Good site Barbara, I've added it to my bookmarks.
    Hope this helps.

  • Help with 2 UNIX Commands using ARD

    Hello All,
    Can someone help me with 2 UNIX commands I would like to set up? The first one... how to delete a range of users within /Users by date (i.e. the oldest user who last logged in "Mar 22 09:40 00796216" to "Mar 25 17:01 01036773"). Currently, I'm using "sudo rm -r " followed by each home directory name separated by a space. It works but to save time, it would be nice to do this all within 1 UNIX command.
    Second, is there a UNIX command where I can delete a range of users by ID numbers? (We have users assigned with an 8 digit ID number. Is there a UNIX command where I can delete users from 12345678 to 23456781?) Again, I'm using "sudo rm -r " followed by each home directory name separated by a space.
    Thank you in advance!
    Mike

    This happens with or without SIM card, with and without wifi... with and without SD card as well-- even bought a new 32GB class 10 SanDisk-- but it still crashed.
    Just an update: Went to the Nokia Care Center yesterday, they reflashed the firmware and I got back the phone within the day... when I went back home to try the phone again... again it kept hanging... in a period of 5 minutes, I had 5 hangs... right from startup, went straight to the cam, took some pics then pinched zoom... and phone simply crashed-- had no SD car, no sim card then.
    So today I went back to Nokia Care Center... they said they will do some more tests and see... but they insist its a software problem, we'll see in a day or 2.

  • How to Move file / call UNIX command using ABAP Program

    Hi, ABAP Guru.
    I need to Cut & Paste file (Move file from one location to another location) on Network Shared Drive using ABAP program.
    But I can't figured out how to do this and what ABAP Command / FM / Method (and maybe UNIX command) that being used.
    Please give me the advice.
    Best regard and Thank you all.
    Nattapash C.

    all methods for your requirements should be in class CL_GUI_FRONTEND_SERVICES

  • Unix command from pl/sql

    How can I call a unix command or run a c program
    from a stored procedure in oracle 9i.

    Or if you want to do a host call then implement the following class as a Java stored procedure.
    import oracle.jdbc.*;
    public class util
    // Executes an operating system command. The command shall be fully qualified.
    // The Java connects with silent login. No environment set-up files are run
    // and no path is set. The mode can be "sync" or "async" for respectively
    // synchronous and asynchronous execution
    static public int OSCmd(String cmd, String mode, String[] output)
    throws IOException, InterruptedException
    System.out.println("OSCmd "+cmd+" ("+mode+")");
    output[0]="";
    // start command
    Process proc = Runtime.getRuntime().exec(cmd);
    if (mode.equals("sync"))
    // get command's stdout and stderr
    InputStream stdout = proc.getInputStream();
    InputStream stderr = proc.getErrorStream();
    String str;
    // Stdout
    BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
    while ((str = br.readLine()) != null)
    output[0]+=str+"\n";
    br.close();
    // Stderr
    br = new BufferedReader(new InputStreamReader(stderr));
    while ((str = br.readLine()) != null)
    output[0]+=str+Long postings are being truncated to ~1 kB at this time.

  • Excuting OS Commands using Printer Driver

    Hello, everyone. I recall reading awhile ago about how one could execute OS commands as a printer driver, for post-processing of Concurrent Program output files, for example.
    Can anyone direct me to some documentation along those lines?
    Thanks,
    --Dave                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I ended up reinstalling the drivers for the Canon from the original CD and that took care of it. Normally I can just copy the PPDs for our particular printers to the PPD folder in the Library/Printers/PPDs folder and it works fine, but for some reason this machine decided it needed everything reinstalled. It's working now.

  • SFTP using Unix command

    Hi all,
    I am trying to upload a file from SAP to a folder in another server.
    Here they want us to use SFTP port 22 which is not supported by SAP by default i guess.
    Could any one give me clear procedure and commands to be used in program in order to upload the in file in the server.
    If you could give the methods and FMs and unix commands used it would be great.
    I went through lot of threads but very few are talking about SFTP and i am not the clear about how to go with it.
    Few say that we need to create and external command in SM59.
    IF it is so can you tell what exactly are the parameter to be given for ex i want to put a file so what would be the parameters and how do we use this command in my program
    Any sample code which puts the file another server???
    Thanx

    Check if your able to do sftp at command line from the server where BPEL is running.
    --Prasanna                                                                                                                                                                                                   

  • How to run an applescript using unix command

    Hi All,
    Can any one help me in giving me the command for running an apple script thru postupgrade shell file in other words i wana run an apple script while running my new installer that will upgrade the old version of application but while installing i want to run an applescript so as i know ill have to give that applescript path in the postupgrade script but how to run it while installation and where to keep it (is it postupgrade). May be in short how can i run apple script thru unix command.

    Use the osascript command.
    In my installer, I use the DropDMG program to build my DMG disk image. It doesn't quit automatically, so I have to do the following:
    osascript -e "tell application \"DropDMG\" to quit"
    Type "man osascript" for more information.

  • Invoking Unix command with java stored procedure

    Hi,
    I have a perfectly working environment and now I am trying to replicate the same in another server. I have a java stored procedure which invokes the Unix command using java Runtime.exec() in my code named "run". I am sure that the code is called and the java class run is resolved in oracle as I could see that in dba_java_resolvers dictionary. But I am not sure whether the function in java is called or whether a exception is thrown. how to identify this? Could there be any thing to do with settings in oracle side? please help me.
    Thanks in advance,
    Marutha

    Hi,
    Do you get any output while running the code?
    I'm testing similar solution and if there are any errors or Oracle can't execute the program due to permissions or other issues the error information will be displayed. Also in the Java class itself you need to catch exceptions and print stack trace to standard output.
    declare
    x number;
    begin
    dbms_output.enable(1000000);
    dbms_java.set_output(1000000);
    x:=system_command.run_command('testconnect.sh');
    dbms_output.put_line('Returned value='||x);
    exception
    when others then dbms_output.put_line('Sql error='||substr(sqlerrm,1,250));
    end;
    <system_command.run_command> - replace with a call to your java stored procedure.

Maybe you are looking for