Calling Unix-Script from within Oracle and store stdout/stderr in table

Hi,
What I want to do is:
1. Calling a UNIX script (e.g. hello.sh) (from inside the Database)
hello.sh
echo “Hello World!“
2. and get the stdout/stderr output back in my Database in a table (e.g. temp_back)
table temp_back
ID     stdout          stderr
1     Hello World!
I think Number 1 isn’t a big problem, but how to get stdout back in DB?
Any solution?
I searched a bit in this Forum and found this Post.
re:Calling Host Command Through Database  Procedures or Triggers
This may be what I am searching for, but can’t access the Link
Since I am not really fit with UNIX and packages/procedures in Oracle it would be nice if you could post a very detailed answer.
(Please no java)
-What packages do I need? (heard DBMS_OUTPUT would be useful)
-example PL/SQL script
Thanks a lot!
Marcus
Environment:
Oracle 9.2.0 DB

Marcus, if you opened the Java sandbox to access any o/s file, you can call any Unix command, shell script, or program, that the Oracle o/s user has exec privs on.
Just remember that there's a very basic Unix environment when you make the call - the settings in the .profile does not apply. Thus PATH for example is not set. When making the call make sure that the complete path is given. As for the environment, that is a problem as you cannot set that and make the call at the same time.
In that case it is much simpler to rather write a Unix shell script that does all for you. Set the environment. Run the command(s). Format output. Etc.
Then you call that Unix script, via Java, from SQL or PL/SQL. Treat the Unix scripts like the Unix-version of stored procedures for your Oracle application.
Some technical details. When you connect to Oracle, a Unix process services you. This can be either a dedicated server process (servicing only your Oracle session) or a shared server process (from the shared service pool of processes).
In either case, it is a Unix process running as a background process (thus detached from any tty device). PL/SQL and SQL are executed by this process. The Oracle JVM created by your session also lives in this process. When you therefore make o/s calls, these calls are made by this process.
Therefore you are limited to what this process can and can't do. E.g. it runs as the oracle o/s user and will fail on accessing paths and commands does the oracle user does not have privs on. Etc.

Similar Messages

  • Calling shell scripts from within Oracle PL/SQL codes

    Hello,
    We are migrating from informix to Oracle. In our Informix Stored Procedure we
    were able to call Unix Shell Script by executing a 'SYSTEM' command, such as:
    CREATE PROCEDURE magazine(flag1, flag2)
    SYSTEM '/pics2/informix/mag.sh' || flag1 || flag2;
    END PROCEDURE;
    How can I write this in PL/SQL? Is there a simillar command for 'SYSTEM' in PL/SQL?
    Thanks

    Mike,
    Wrong forum, for this question, suggest you ask it in the PL/SQL forum.
    Jim Stern

  • Calling UNix Script from portal Form

    Has anyone conquered this issue through jav or plsql. I need to call a unix script from the portal form when I select the insert button.

    I have several very convoluted ways which all work, but I have always thought there should be more straightfwd ways. Fundamentally the easiest way to call something from the Insert button is to add some PL/SQL code before (or after) the "doInsert();" call in the Insert Button event handler.
    What seems to be lacking is the ability to get from pl/sql to the o/s. So until we know how to do that you have to call a method in Java to execute o/s commands - specifically you can use Runtime.getRuntime().exec(cmd); where Runtime is a class in java.lang, and cmd is the actual o/s command (script or whatever).
    How to call this Java is then where you have several options:
    1. Compile this piece of Java into the Oracle DB as a SP.
    2. Deploy this piece of Java within a Java servlet on a 9iAS instance. Then have another SP call this servlet using the utl_http package (begin_request and other sp's within package).
    Which options would depend on several factors including your preference but most importantly whether you have a DB or a 9iAS instance on the machine where you want to execute the script. If you have neither you have a problem. In such cases I have used a standalone OC4J container which has a very small footprint.
    As I said these methods are all quite convoluted and if anyone else has anything better I would like to know (but they work quite reliably).
    Cheers.
    Anton.

  • Call Unix Script from JSP.

    Hi,
    I need to run a unix script from a JSP page.
    JSP pages reside on a different machine.
    How can i call the unix script resides on different machine from JSP.
    Thanks,
    Narendra

    yah. I can access that machine telnet and having all credentials of that system.
    Can you please share the code needed for this.
    Thanks,
    Narendra

  • Download files from the URL and store them in the table

    Hello,
    I want to download files from the URL and want to store them in the table.
    Can I do it using sql/pl-sql.
    Please help me on this.
    Thanks,
    Rajendra Yadav

    Never tried it before...
    Is this what you are talking about?
    http://www.oracle-base.com/articles/10g/file-upload-download-procedures-10g.php
    Cheers,
    Manik.

  • Running shell scripts from within oracle. A big task is forgotten

    Dear List,
    I have some shell shell scripts which do some tasks on the linux OS level.
    I am calling the Korn scripts using a java class, which in turn is being called from a PLSQL function.
    All but one of the 10 script works fine. This is the script which does the most work, and takes on average 40 minutes usually.
    Why does Oracle forget the running of the shell script? I wait in my PLSQL function for the return code, but it never comes. The scripts I have not written myself !
    I look forward to your reply on this matter.
    regards
    Ben

    Hi
    If you are using the Oracle database 10g, the new dbms_scheduler package allows you to run shell scripts. The dbms_scheduler.create_job procedure have one parameter called the job_action in which you specify the full path of the shell script.
    I hope this will help

  • Security issues with calling web services from within Oracle?

    I'd like to use a trigger to initiate pushing data to a web service, so I thought we should call the web service from PL/SQL in a DBMS job, or perhaps create a .NET stored proc to call the service. Our DB Lead is concerned about security, since the standard model is for clients to call the database, and not for the database to function as a client.
    Does this pose any security risk? Can you refer me to any best practices or articles on this?
    Thanks in advance.
    Edited by: Kit.net on Nov 9, 2010 11:28 AM

    First, a trigger is there to for a single sole purpose - guaranteeing the integrity of the data and the transaction. It is not there to interact with external services and processes (like mail, web and other services). Doing that exposes the transaction to those other processes/services. The transaction can now fail. not because of a business rule validation, but because of a network error when the trigger accesses an external service. How on earth can a business transaction fail when the transaction is valid, but a the transaction's trigger hit an external access error!?
    And what happens do that event you have fired off in the trigger, when the transaction is rolled back? How do you undo that event you have created in the trigger that was based on uncommitted data?
    So using a trigger like this is simply stupid (and yes, I have seen it too often in practice with horrible results to sugarcoat such an idiotic approach).
    As for calling a web service from the database, using the database as the client in such a case. This is not a security risk. This is not unusual. In fact, it is very common in my experience. We have a lot of databases, ranging from SE to EE and several RAC clusters. All of them function as a client at some stage during processing. Some use a db link - and as a client fire off a SQL via that db link to a database server to obtain data. Some use ftp and act as a ftp clients, transferring processed data (XML format) to a server. Some call web services to extract data from 3rd party systems to reconcile the differences between local data sets and 3rd party data sets..
    This is common between server and server. I do not see anything unusual in the database server using another server (and acting as a client when it does). Security between servers should not be a major problem (in fact, it can easily be done in a very robust way using trusted and encrypted communication).
    The problem occurs when a client connects to the server and client and server roles are swapped at some stage (like the server "writing" a file directly to the client's filesystem). This very seldom makes any sense. And this is where authentication and security become an issue.

  • Problem when call unix script from jsp

    Dear all,
    I want to list all the file in a unix directory and display in jsp.
    And the directory have below files:
    -tmp1.txt
    -tmp2.txt
    -log.txt
    -blog.txt
    I used the runtime object and Runtime.exec ('ls -lrt') which can get the file list suceesful.
    But when i use Runtime.exec('ls -lrt tmp*) , then it get nothing.
    Pls kindly help.
    Tks

    I agree with DrClap. But you may need to do "shell wild-card expansions" for something else. Your type of question is asked quite frequently in the forums. Do a little more research. As a hint. Java will not expand your "tmp*". A Unix shell will however. So you need to pass your little command to a Unix shell and have java execute the shell command along with your "ls -lrt tmp*".

  • Call a unix script from pl/sql package

    Hi,
    Using 11.2.0.3 on AIX.
    Is it possible to call unix script from pl/sql package?
    I am cretaing a file in a directory but would like this to automatically be written to an archive directory as well.
    Could either use 2 utl_file.put_lines to 2 separate directories or 1 utl_file and cal script to archive file in another directory.?
    Thoughts?
    Thanks

    user5716448 wrote:
    What am I doing wrong?think how file name will look like:
    SQL> select 'file_name' || to_char(sysdate,'DD/MM/YYYY HH24:MI:SS') from dual;
    'FILE_NAME'||TO_CHAR(SYSDATE
    file_name15/08/2012 11:47:51Will AIX swallow such name? Obviously not. And, unfortunately, UTL_FILE.FCOPY doesn't raise an error in such case. So use someting like:
    UTL_FILE.FCOPY ('SOURCE_DIR',v_FILE_NAME,'DEST_DIR',v_file_name||to_char(sysdate,'DD_MM_YYYY_HH24_MI_SS'));SY.

  • Calling unix script using oracle forms

    we have to call unix script using oracle forms , a trigger in form calls stored procedure on database
    that stored procedure on database calls a oracle shared library
    but since the only listener account for oracle on our unix server is oralist , whenever a call is made to the unix script from the oracle form , the unix script is executed by oralist user
    but issue that we are having now is since oralist is specific for listening connections from orale we dont want to use this user to establish SFTP on it to avoid any issues with oralist
    we want the sftp to be established on soem other useraccount , so is it possible to do something so that the script is executed by an account other that oralist.

    I'm not a Linux/Unix specialist, but I think this may work: let your database call a shell script that does a su command before running the actual script:
    su - other_account
    your_script.sh

  • More on unix script from pl/sql

    Hi All,
    There was this discussion on starting unix scripts from within a pl/sql stored procedure started on August 31.
    All comments were targeted towards an oracle 8X solution.
    Does anyone have a solution for 7.3.4?
    Somebody mentioned something about using dbms_pipe package.
    So, just to rephrase the problem:
    - Need to execute any unix command/script from within a pl/sql block (stored procedure). Instance is oracle 7.3.4
    Thanks!
    Enrique

    Hi Juan,
    You can try this solution:
    enable in the the init file the parameter
    utl_file_dir="target_directory"In this way You permit the the DB to writing directly to the filesistem in the directory You specified.
    After restarting the istance You may write Your own code that, using the supplied package UTL_FILE, writes a file in that directory (es. my_script.sh)
    Then, instruct the cron daemon to execute every 1 minute this command.
    You may append to the script the self-destruction after the execution.
    I hope that this will help You.
    Max

  • Calling external programs from within a Tomcat application

    I've got a fairly complex existing Tomcat application (which is packaged and built as a .war file) which I'm trying to edit so that it calls a Perl script part way through the processing, which will generate an XML file used later on. I think I've worked out how to call external scripts from within Java, but at the moment when I try and access the application via Tomcat the application either hangs or bails out (I don't know which, as the log files unhelpfully don't give any error messages).
    The code which is causing the problem looks like this:
    System.err.println("Calling runtime...");
    Runtime runtime = Runtime.getRuntime();
    System.err.println("Executing process...");
    Process process = runtime.exec("/path/to/ysearch.pl 'News' '\"search query\"' 'file");
    System.err.println("Waiting for process...");
    int exitVal = process.waitFor();
    System.out.println("Exited with error code: " + exitVal);The code gets as far as "Executing process..", beyond that there is nothing in the log file so I presume the runtime.exec() call is where the problem is. I'm not interested in reading the output from the script (there shouldn't be any), so that's not an issue, and the permissions on it allow anyone to read or execute ysearch.pl so I don't think there's a problem in that area.
    Does anyone have any suggestions which I could try to get this to work? I've only been using Tomcat for a week (I'm picking up on someone else's code) so I might have made a beginner's mistake. I'm using Tomcat 5 on Fedora Core 7, and Java 1.5.0_01 (I can't easily change any of those).

    I'm not sure, but I thing that overhead caused by calling du cannot be big enough to matter even on older machines.
    But, when calling du from Perl script you are also invoking shell, and this can be a little bit more 'heavy'.

  • Executing a Perl Script from within a Servlet

    I'm trying to call a script from within a servlet.This is the code i'm using:
    Process process = Runtime.getRuntime().exec(new String[]{"sh","-c",script,nick,pass});
    InputStream input = process.getInputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int i;
    while ((i=input.read())!=-1) {
    baos.write(i);
    System.out.println(baos.toString());
    I can`t make it work.This is the output i'm getting.
    java.io.IOException: CreateProcess: sh -c /home/script.sh user pass error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.(Win32Process.java:66)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:551)
    at java.lang.Runtime.exec(Runtime.java:477)
    at java.lang.Runtime.exec(Runtime.java:443)
    at controllers.EmailAcountCreate.doPost(EmailAcountCreate.java:34)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    Thanks in advance.

    I am facing the same problem. Could you please post the answer if you have one now. Please treat this as very urgent.

  • 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

  • Calling startrfc.exe from within a vbs script

    Hello, can someone help me please
    I am trying to process xml idocs into SAP on a Windows 2008 server. I have written a vbs script to process the file and am trying to call STARTRFC.EXE from within the vbs script. However I keep getting an error that it cannot open the file. The code is shown below. I have changed the server name and gateway and user/passwd for security. I'm passing the filename as a variable (str_expfile) but it does not seem to be able to extract the actual file name from the variable. I know from past experience that you can pass it variables if its running on a unix box and in a shell. But for some reason it not decipering the variable name in the vbs script
    Set objShell = CreateObject("Wscript.Shell")
    str_startrfc = "D:\usr\sap\SID\SYS\exe\uc\NTAMD64\startrfc.exe -d SID -3 -h hostname -s 00 -g hostname -x sapgw00 -u user -p passwd -c 100 -l EN -t -F EDI_DATA_INCOMING -E PORT=MYPORT -E PATHNAME=str_expfile"
    objShell.Run str_startrfc, ,True
    The error I'm getting is shown below:
    ERROR file opened at 20110510 134219 GMT Daylight Time, SAP-REL 700,0,278 RFC-VER 3 1200864 MT-SL
    T:2584 Error in program 'startrfc': ======> Error at OPEN 'str_expfile' (check file)
    T:2584 Error in program 'startrfc': <* RfcReceive [1] : returns 3:RFC_SYS_EXCEPTION
    T:2584 Error in program 'startrfc': <* RfcCallReceive [1] : returns 3:RFC_SYS_EXCEPTION
    Thanks
    Regards
    Steve

    Hi Markus
    Unfortunately I can't do that because I need it to process hundreds of files one after another and I would have to hard code the file path each time. That's why I need it automated.
    Can startrfc.exe not take a variable for the pathname in a vb script? It works fine in a unix shell. We are migrating from unix to windows and I need to convert all my unix scripts into vb scripts.
    I notice there is a nother rfc type program available, can I use rfcexec.exe instead of startrfc.exe and would it take variables?
    Thanks
    Regards
    Steve

Maybe you are looking for

  • RE: Typekit...how do I move the code from an old account to my new account under the Creative Cloud?

    RE: Typekit...how do I move the code from an old account to my new account under the Creative Cloud? W/out (preferably) interuption to the website in question? Thanks!

  • RE80 - Error while Creating Business Entity

    Dear All, I m getting one error while creating the Business Entity using RE80 Tcode. The error is "Section code is Mandatory, as EWT is active". Please tell me how to solve this issue. waiting for your solutions. Regards, Sanket.

  • Problem with File panel and Local files

    I am having a couple of problem using Dreamweaver  (which may be related) and can't find any appropriate help on the web site. I have created a small website and have it up and running.    I'm now trying to do some minor modifications.     But Dreamw

  • Filter Function in MDX statement

    Hi Experts, I have a question on MDX, i hope this is the right place to post. I want to exclude a certain value of an infoobject in MDX output. How can i achieve this?

  • Resetting iMac G5

    We just purchased a new iMac to replace our older G5 iSight. I'd like to sell the G5 but I want to wipe the hard drive and reinstall the OS first. I've been running into some difficulty. The computer was a hand me down, however, I do have what I beli