Unix script in Oracle Pl/sql

I created a unix script which is automatically transfer the file from one instance to other .Now i want to call that script from pl/sql ,how can i do that
Kindly give the suggestion

Check the following link. It contains the steps to execute system commands from PL/SQL.
http://www-rohan.sdsu.edu/doc/oracle/server803/A54642_01/ch8.htm

Similar Messages

  • 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

  • How to run a unix script from oracle warehouse Builder

    Hi,
    can any one share the information about, running the unix script or scripts using oracle warehouse builder.
    Regards,
    Ak

    One way is define a workflow. Inside the workflow you put
    1)an external process that "points to" the shell script and then
    2)put the mapping
    The external process must have the "COMMAND" parameter set to the name of the shell script. If the script has parameters you must put them in the "PARAMETERS LIST" separated by "?" (for example, ?par1?par2).
    The path where OWB executes the external process I think is the ORACLE_HOME of the OWB.
    f you don't use workflow, you can try with this more complex solution. I tried with 9i and OWB 9.2 and it's working well.
    You create an autonomous procedure (within a package or not) :
    CREATE PROCEDURE Extract_Email_List
    DECLARE
    PRAGMA AUTONOMOUS_TRANSACTION;
    And use the sys.shell script that you need your dba/unix admin to install first of all, with a call like that.
    sys.shell('sh ' || txt_dir_name || '/send_email_marketing.sh ' || txt_dir_name || ' ' || email_addr );
    Then you import your procedure into OWB and use it in your mapping with the "pre-mapping" icon (you can set parameters for your proc with constants if you want).
    To implement sys.shell, go to metalink and find "Note:168065.1" - "How to call a UNIX shell script from PL/SQL".
    Once it's done once, it's not so bad. But I would still recommend the workflow approach also..
    I hope this helps.

  • Unix SCRIPT CALL FROM PL/SQL

    How can I call an unix script from a PL procedure ?

    http://www.orafaq.com/scripts/c_src/extproc.txt

  • Execute Unix script file using PL/SQL.

    Hi all,
    Is there a way to execute a PL/SQL procedure which call the Unix(AIX) OS script file.
    My version of Oracle is 7.3.
    Thanks.

    As Justin says, Java stored procedures is one way
    else if you dont know Java and are familiar with C,
    then you can create external routines in C
    and use them in procedure.
    Works with 8i and above( I believe)
    Cheers
    Ashwin N.

  • Invoke and Execute Unix command from Oracle PL/SQL

    Dear All,
    I am currently working in the development of multi user application in ORACLE.
    My problem is,
    I have to remove a temporary file created in unix server when a particular condition is satisfied in a PL/SQL proccedure.
    I searched for this and got solution to use DBMS_PIPE package.
    Can you help me how to pack the content 'rm file_name' from different users working in different sessions and how to execute. Can you please explain me how the server manages calls from different sessions and replies to individual sessions.
    Thanks in advance,
    Shenbaga.

    Well if doesn't raise an exception it succeeded. Is that sufficient acknowledgement?
    Cheers, APC

  • Help needed in Unix script for oracle 9i

    Hi gurus,
    I'm working on oracle 9i in solaris, i would like to calculate the amount of archived logs generate per day. Can anyone please help me to find that.
    Thanks

    Put the following lines in a script and it should work for you.
    SET feedback off
    SET line 200
    COL NAME FOR a100
    -- counts the no of archives generated today
    select count(*) "No. of Logs for today" from v$archived_log where to_char(completion_time,'DD-MON-YY')=to_char(sysdate,'DD-MON-YY');
    -- lists all archive generated for the day
    select name,blocks*block_size as "Size in KB" from v$archived_log
    where to_char(completion_time,'DD-MON-YY')=to_char(sysdate,'DD-MON-YY');
    -- shows total size in KB
    select sum(blocks*block_size) "Total Log Size for day in KB" from v$archived_log
    where to_char(completion_time,'DD-MON-YY')=to_char(sysdate,'DD-MON-YY');
    Hope this helps.
    Thanks
    Siba

  • How ro run unix script freom pl/sql - dbms_scheduler 11.2.0.3

    Hi,
    Using 11.2.0.3 and have a unix script which works fine.
    Want to run this unix script every time a piece of pl/sql runs
    have put below in but doesn't actually run it.
    How can we achieve this?
    Many Thanks
    idea is that file we create locqally on server is copied to another via the unix script caled form pl/sql
    DBMS_SCHEDULER.create_program (
       program_name => 'test_executable_prog',
       program_type => 'EXECUTABLE',
       program_action => '/oracle/jm/data/dataout/copy_tcfile',
       number_of_arguments => 0,
       enabled => TRUE,
       comments => 'CREATE_PROGRAM test using a schell script.');Tried below but no joy
    -- Shell Script (OS executable file).
    /*DBMS_SCHEDULER.drop_program(program_name => 'por_copy_files');
    DBMS_SCHEDULER.create_program (
       program_name => 'por_copy_files',
       program_type => 'EXECUTABLE',
       program_action => ' /oracle/jm/data/dataout/copy_tcfile',
       number_of_arguments => 0,
       enabled => TRUE,
       comments => 'CREATE_PROGRAM test using a schell script.');
    DBMS_SCHEDULER.create_job (
        job_name        => 'por_copy_files_job',
        program_name    => 'por_copy_files',
        start_date      => null,--SYSTIMESTAMP,
        repeat_interval => null,--'freq=hourly; byminute=0',
        end_date        => NULL,
        enabled         => TRUE,
        comments        => 'Job defined by existing program and inline schedule.');Edited by: user5716448 on 03-Oct-2012 08:35
    Getting message when look in all_scheduler_job_run_details
    ORA-27369: job of type EXECUTABLE failed with exit code: No such file or directory
    even thoug hfile exists
    Edited by: user5716448 on 03-Oct-2012 08:50

    When run for unix command line which o.k
    get
    AUTHSTATE=files
    A__z=! LOGNAME
    COLUMNS=132
    EDITOR=vi
    ENV=/home/oracle/.kshrc
    HOME=/home/oracle
    LANG=en_US
    LC__FASTMSG=true
    LOCPATH=/usr/lib/nls/loc
    LOGIN=oracle
    LOGNAME=oracle
    MAIL=/usr/spool/mail/oracle
    MAILMSG=[YOU HAVE NEW MAIL]
    MAIL_HOST=prdikw01
    NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat
    ODMDIR=/etc/objrepos
    ORACLE_BASE=/oracle/app/oracle
    ORACLE_HOME=/oracle/app/oracle/product/11.2.0/dbhome_1
    ORACLE_SID=IKW
    ORACLE_TERM=vt100
    ORATAB_PATH=/etc
    PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin:/usr/local/bin:/etc:/usr/sbin:/usr/ucb:/h
    ome/oracle/bin:/usr/bin/X11:/sbin:/oracle/app/oracle/product/11.2.0/dbhome_1/bin:/oracle/app/oracle/product/11.2.0/dbhome_1/OPatch
    PS1=[$ORACLE_SID]$PWD $
    PWD=/oracle/jm/data
    SHELL=/usr/bin/ksh
    TERM=xterm
    TMPDIR=/tmp
    TZ=GMT0BST,M3.5.0,M10.5.0
    USER=oracle
    _=/usr/bin/env
    dba=/home/oracle/dbaWhen run from pl/sql
    get
    ORA-27369: job of type EXECUTABLE failed with exit code: 255
    STANDARD_ERROR="execve: Exec format error"when try
    dbms_scheduler.create_job(
    job_name => 'POR_JOB',
    job_type => 'EXECUTABLE',
    job_action => '/oracle/jm/data/copy_tcfile',
    start_date => SYSTIMESTAMP,
    number_of_arguments=>0,
    enabled => true,
    auto_Drop => true,
    comments => 'Demo');Above code in pl/sql where create job and schedule job separately gives file not found message even though give full path

  • 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.

  • Run Shell script from oracle plsql

    OS--> Linux
    Version--Oracle 10g
    I want to run a shell script from oracle PL/sql. I know dbms_scheduler can be used to create job , enable job and run it .
    But I have a requirement where I need to know if my script ran successfully or not. Something like a return code back to oracle.
    So that I can run appropriate code depending on return code of executed Script.
    Kindly help !!

    Online documentation was invented for a reason.
    And this reason was not would look it, as a volunteer, on your behalf, and post it in this forum.
    All procedures are documented. There are examples for most facitlities on Asktom, and there is Morgan's Library at [http://www.psoug.org]
    Sybrand Bakker
    Senior Oracle DBA

  • 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

  • Unix script output sql result to terminal

    Hi,
    I run the script below within a unix script. the query runs but only outputs the first line. I need the whole results output to the terminal.. please let me know if I am doing something wrong. thanks
    ORACLE_SID=orcl
    export ORACLE_SID
    SHELL=/bin/sh
    db="username/password"
    sqlplus -s $db <<xxx
    set serveroutput on
    define yy=100
    whenever sqlerror exit yy
    begin
    declare
    Dyn_table_name VARCHAR2(100);
    Dyn_query_string VARCHAR2(4000);
    Type csr_dyn IS REF CURSOR;
    csr_dyn1 csr_dyn;
    col1 varchar2(200);
    col2 varchar2(200);
    col3 varchar2(200);
    col4 varchar2(200);
    col5 varchar2(200);
    begin
    Dyn_table_name :='''my_table''';
    Dyn_query_string :='SELECT b.session_id ,s.serial#,NVL(b.oracle_username,''(oracle)'') AS username,'
    ||'a.object_name,b.os_user_name FROM dba_objects a,v\$locked_object b,v\$session s'
    ||' WHERE a.object_id =Upper(b.object_id)and b.session_id=s.sid and a.object_name='||Dyn_table_name;
    /*dbms_output.put_line(Dyn_query_string);*/
    dbms_output.put_line('SID'||' '|| 'serial#' || ' '||'USERNAME'||' '||'OBJECT_NAME'||' '||'OS_USER_NAME');
    dbms_output.put_line('------------------------------------------------------------------------------------');
    OPEN csr_dyn1 FOR dyn_query_string;
    LOOP
    FETCH csr_dyn1 INTO col1,col2,col3,col4,col5;
    EXIT WHEN csr_dyn1%NOTFOUND;
    dbms_output.put_line(col1||' '|| col2||' '|| col3 || ' ' || col4 ||' '|| col5);
    END LOOP;
    EXCEPTION WHEN OTHERS THEN
    dbms_output.put_line(to_char(sqlcode)|| ' '|| sqlerrm);
    end;
    end;
    set serveroutput off
    exit
    xxx

    Sorry all your suggestion did not work ( the log file had this error message
    Usage 1: sqlplus -H | -V
    -H Displays the SQL*Plus version and the
    usage help.
    -V Displays the SQL*Plus version.
    Usage 2: sqlplus [ [<option>] [<logon>] [<start>] ]
    <option> is: [-C <version>] [-L] [-M "<options>"] [-R <level>] [-S]
    ... I know its possible to login into sqlplus and run the querry, but I want it as a script which would output this kind of result to the screen
    SESSION_ID SERIAL# USERNAME OBJECT_NAME      OS_USER_NAME
    251     30330     PRD my table     oracle
    335     11624     PRD     my table     oracle
    469     2592     PRD     my table     oracle
    849     8619     PRD     my table     oracle
    934     40211     PRD     my table     oracle
    955     15043     PRD     my table     oracle
    is it possible or am I asking for the impossible...!!! I appreciate your suggestion... you can alter the script I put up and paste the correction so that I can see cleary how you made it work for you.

  • Oracle career with unix scripting?

    hi
    iam working in a reputed mnc with CMMi level 5 .started as fresher (BE I.T) i have around 1.6 years of experiance in unix scripting/oracle sql production support.
    with learning of sql and shell scripting
    i want to make my career in oracle which should be more dynamic,learning and creative not like in production support which have monotonus life.
    could anyone please guide me about what career path i should choose ?
    DBA , i have heard is montonous job too with same routine backups,no creativity with nightshifts and all, but it is more stable as people said. I have no experiance of it.
    second devolper track in sql/pl sql having its own limitations like less demand, less financial growth etc. and people usually wants to shift in other area like BO
    i don`t have any info about others areas like that i would like to explore
    1)Datawarehousing
    2)Oracle apps
    3)Business objects (BO reporting)
    4)Oracle CRM etc
    5)Others (thats all i know,please add some others if they are creative )
    iam really confsused now which way to chosse. and how to jump in other company on wat basis?
    preparing for OCA right now but uncertain for career.
    Seeking good help from forum experts.

    "with learning of sql and shell scripting"
    Ah, very good move, so you must pick my tool, it is all about managing Oracle DB through Korn shell http://www.smenu.org.
    As of your question, the answer is in your mood and preference.
    Oracle DBA: Definitely more money, less opportunity. the job is dwindling somehow due to Grid automation and budget restriction.
    It is not that you don't need DBA, but manager thinks they can do without and don't (try) replace them. Pressure on DBA is a myth: more work = more money = happy DBA until wife run away.
    Developer : Definitely less money, not necessary more opportunity unless you have java EE. no shift but more pressure: Projects are always in late, usually in the development area, not in the infrastructure.
    One funny thing I noticed during these last 15 years, is that DBA have usually more children than others people (unix sys admin or Dev). Probably related to better earning.
    DBA can be boring or passionate depending on your own knowledge, most of others DBA I know are still in the job, only one is now JAVA EE guy.

  • Oracle SQL template to create re-usable DDL/DML Scripts for Oracle database

    Hi,
    I have a requirement to put together a Oracle SQL template to create re-usable DDL/DML Scripts for Oracle databases.
    Only the Oracle DBA will be running the scripts so permissions is not an issue.
    The workflow for any DDL is as follows:-
    1) New Table
    a. Check if the table exists from the system/admin views.
    b. If table exists then give message "Table Exists"
    c. If table does not exist then execute DDL code
    2) Add Column
    a. Check if Column exists for a given table from system/admin views
    b. If column exists in the specified table,
    b1. backup table.
    b2. alter table to make changes to the column
    b3. verify data or execute dml script convert from backup to the new change.
    c. If Column does not exist
    c1. backup table
    c2. alter table to add column
    c3. execute dml to populate column with default value.
    The DML scripts are for populating base tables with data required for business operations.
    3) Add new row
    a. check if row exists by comparing old values of each column with new values to be added for the new record.
    b. If exists, give message row exists
    c. If not exists, add new record.
    4) Update existing record (We have createtime columns in these tables so changes can be tracked)
    a. check if row exists using primary key.
    b. If exists,
    b1. deactivate the record using the "active" column of the table
    b2. Add new record with the changes required.
    c. If does not exist, add new record with the changes required.
    Could you please help with some ideas which can get this done accurately?
    I have tried several ways, but I am not able to put together something that fulfills all requirements.
    Thank you,

    First let me address your question. (This is the easy part.)
    1. The existence of tables can be found in DBA_TABLES. Query it and and then use conditional logic and execute immediate to process the DDL.
    2. The existence of table columns is found in DBA_TAB_COLUMNS. Query it and then conditionally execute your DDL. You can copy the "before picture" of the table using that same dba view, or even better, use DBMS_METADATA.
    As for your DML scripts, they should be restartable, reversible, and re-run-able. They should "fail gracefully" on error, be written in such a way that they can run twice in a row without creating duplicate changes.
    3. Adding appropriate constraints can prevent invalid duplicate rows. Also, you can usually add to the where clause so that the DML does only what it needs to do without even relying on the constraint (but the constraint is there as a safeguard). Look up the MERGE statement to learn how to do an UPSERT (update/insert), which will let you conditionally "deactivate" (update) or insert a record. Anything that you cannot do in SQL can be done with simple procedural code.
    Now, to the heart of the matter...
    You think I did not understand your requirements?
    Please be respectful of people's comments. Many of us are professionals with decades of experience working with databases and Oracle technology. We volunteer our valuable time and knowledge here for free. It is extremely common for someone to post what they feel is an easy SQL or PL/SQL question without stating the real goal--the business objective. Experienced people will spot that the "wrong question" has been asked, and then cut to the chase.
    We have some good questions for you. Not questions we need answers from, but questions you need to ask yourself and your team. You need to reexamine this post and deduce what those questions are. But I'll give you some hints: Why do you need to do what you are asking? And will this construct you are asking for even solve the root cause of your problems?
    Then ponder the following quotations about asking the right question:
    Good questions outrank easy answers.
    — Paul Samuelson
    The only interesting answers are those which destroy the questions.
    — Susan Sontag
    The scientific mind does not so much provide the right answers as ask the right questions.
    — Claude Levi-Strauss
    You can tell whether a man is clever by his answers. You can tell whether a man is wise by his questions.
    — Mahfouz Naguib
    One hears only those questions for which one is able to find answers.
    — Friedrich Nietzsche
    Be patient towards all that is unresolved in your heart and try to love the questions themselves.
    — Rainer Maria Rilke
    What people think of as the moment of discovery is really the discovery of the question.
    — Jonas Salk
    Judge a man by his questions rather than his answers.
    — Voltaire
    The ability to ask the right question is more than half the battle of finding the answer.
    — Thomas J. Watson

  • Copying SQL Script from Oracle SQL Developer into Excel with formatting

    I need to copy a SQL Script into Excel in order to develop some VBA code. Is there any nice way that I can copy SQL Script from Oracle SQL Developer into Excel and retain its formatting? I am a stickler for having legible, readable SQL and like to have all my columns lined up and aliases lined up. When we used to use SQL Navigator, the tab formatting seemed to copy and paste just fine. Now that we have migrated to Oracle SQL Developer, the formatting seems to get all messed up.
    And suggestions are greatly appreciated and Thanks in advance for your review and am hopeful for an answer.
    Thanks.
    PSULionRP

    I suppose you want a real tabulator instead of spaces. You can configure this in the preferences (SQL Formatter - Oracle). You have to apply it then to your existing code (e.g. CTRL-F7), but new code should get it right from the start.
    Hope that helps,
    K.

Maybe you are looking for

  • Field editing in 10.4

    Now that I've installed 10.4, there is no more auto-fill in the genre field nor, when you're editing in the main window, is there the ability to tab from one field to the next anymore. Did I miss a setting or did Apple leave this feature out of 10.4?

  • Airport no longer connects to OPEN wireless networks

    Lots of people seem to think that their airport keeps dropping the connection to OPEN wireless networks because of the 2008-001 airport update. That is probably only true for a Macbook 2,1 (aka Macbook Core 2 Duo). I had the issue on my Macbook 1,1 (

  • BOM Uploading through LSMW

    Hi Experts,   I am Uploading BOM through LSMW by Direct Input method. I am having the following queries,   1.  In that BOM I have Header data and Item data. While doing the Step 7(specify file) it accept the text file only not the Excel file. If I as

  • When Uploading Podcast, Getting a Connection Interrupted Message

    Hey everyone, I'm trying to upload my podcast from iweb to itunes (as I usually do anyway) and I am getting this error message which I've never seen before; Our connection was interrupted to this feed, possibly due to a timeout. The host did not acce

  • Error in Subquery in BIP11g

    We have a Query in BIP11g and it fails on this:       WHERE S.STUDENTNUMMER = SE.STUDENTNUMMER      AND SE.OPLEIDING = O.OPLEIDING      AND SI.OPLEIDING = O.OPLEIDING AND NVL(:P_COLLEGEJAAR,12) IN ( SELECT NVL( :P_COLLEGEJAAR,12) JAAR FROM OST_STUDEN