Unix script in PL/SQL

I am building a txt file using UTL_FILE in PL/SQL and need to email it using a Unix script. How can I add the Unix script to the end of the PL/SQL?

Well, on the UNIX side of things I have simply used mail -s <subject> <email_address> < <text or file> to send mail inside of a UNIX script and it works fine.
or you can use cat <some text> | mail -s <subject> <email_address>
UTL_SMTP works well if you want to have less moving parts and have one script compiled inside the database. I guess if you already have the UTL_FILE working, it would be less work to just add in the code to mail from the UNIX script.
HTH
ReedK

Similar Messages

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

  • Unix Scripts and PL/SQL

    I want to run a UNIX script via PL/SQL. I want the script to be run with no assistance from an outside source. The script contains a 'ls'. Is this possible and if so, how.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Christopher Racicot ([email protected]):
    You can use an "external procedure", written in C, which then uses the C runtime library to access the UNIX shell. This features is
    also known as "callouts".
    We will likely add better native support
    in PL/SQL for various operating system
    activities in a future release.<HR></BLOCKQUOTE>
    Can you invoke Perl from within PLSQL?

  • 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

  • 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

  • Starting Unix Script from pl/sql procedure

    I would like to start any unix shell script out of oracle.
    I don't want use DBMS_PIPES, because then I always need a unix daemon.
    Is there a package wich allows to a call similar to
    "os_result := dbms_systemcalls.call_unix_system
    ('/usr/bin/ls -la');
    null

    What version of Oracle are we talking about here? If it's v8 then I think what you're after is a pl/sql external procedure which I can tell you how to set up.
    Andy
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Christoph:
    I would like to start any unix shell script out of oracle.
    I don't want use DBMS_PIPES, because then I always need a unix daemon.
    Is there a package wich allows to a call similar to
    "os_result := dbms_systemcalls.call_unix_system
    ('/usr/bin/ls -la');<HR></BLOCKQUOTE>
    null

  • 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

  • How to prepare for Converting UNIX shell scripts to PL/SQL

    Hi All
    I was said, that i may have to convert a lot of unix shell script to PL/SQL, what are the concepts i need to know to do it efficently,
    what are the options PL/SQL is having to best do that.
    I know the question is little unclear, but I too dont have much inputs about that i'm sorry for that, just its a question of how
    to prepare myself to do it the best way. What are the concepts i have to be familiar with.
    Many Thanks
    MJ

    Just how much work is involved, is hard to say. Many years ago I also wrote (more than once) a complete ETL system using a combination of shell scripts, SQL*Plus and PL/SQL.
    If the PL/SQL code is fairly clean, uses bind variables and not substitution variables, then it should be relatively easy to convert that PL/SQL code in the script to a formal stored procedure in the database.
    There is however bits and pieces that will be difficult to move into the PL/SQL layer as it requires new software - like for example FTP'ing a file from the production server to the ETL server. This can be done using external o/s calls from within PL/SQL. Or, you can install a FTP API library in PL/SQL and FTP that file directly into a CLOB and parse and process the CLOB.
    Think of Oracle as an o/s in its own right. In Oracle we have a mail client, a web browser, IPC methods like pipes and messages queues, cron, file systems, web servers and services, etc. And PL/SQL is the "shell scripting" (times a thousand) language of this Oracle o/s .
    In some cases you will find it fairly easy to map a Unix o/s feature or command to one in Oracle. For example, a Unix wget to fetch a HTML CSV file can easily be replaced in Oracle using a UTL_HTTP call.
    On the other hand, techniques used in Unix like creating a pipe to process data, grep for certain stuff and awk certain tokens for sed to process further... in Oracle this will look and work a lot different and use SQL.

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

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

  • 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

  • Executing Unix scripts from a stored procedure

    From the sql*plus windows, I am able to execute the host command and '!sh' commands; but I need to ececute Unix scripts from a stored procedure. Hoe can I do this? Where can I get good documentation on this? Any help would be greatly appreciated!
    Thanks..

    Hi,
    U can use external procedure ( newly added feature in 8.0.3 onwards) and call any shared library. From shared library u can execute it.
    One sql command is there HOST(' '). U can run a OS command. But u can not use it in PL/SQL.
    U can call pls sql from shell !!!!!..
    Thanks...
    Boby Jose

  • How can I exit my UNIX script when my PLSQL script in it calls an error?

    hello.
    I hope someone can help with my error handling and exiting-in-the-right-place problem.
    I have several PLSQL scripts that are called from a UNIX script to insert/update employee records in ORACLE Financials.
    At the end of the UNIX script, depending on whether an entry has been created in the errors table should depend on whether the UNIX script stops or not. Trouble is, its stopping too early everytime even though the the record has been inserted correctly. Please can someone either advise on what I'm doing wrong or suggest an alternative..
    This the end of the PLSQL script that inserts the entry into errors table if theres an error..
    WHEN OTHERS    THEN       ROLLBACK;
          err_msg := SUBSTR (SQLERRM, 1, 350);
          insert into kpmg_error_check (concurrent_id,module,narrative,status,creation_date,created_by)
                                values(0,'TEMPLOYEE_DTLS.sql',err_msg,'ERROR',SYSDATE,'Feldman');
         commit; This is the end of the UNIX script that looks at the table..
    echo " "
    echo "**** `date +%H:%M:%S` - Checking if TEMPLOYEE_DTLS.sql ran OK"
    error_check=`sqlplus -s $user_id @$SU_TOP/sql/SUTEMPCHK.sql 1`
    if `echo $error_check` -ge 1
    then
    # Load failed
    echo " "
    echo "**** `date +%H:%M:%S` - TEMPLOYEE_DTLS has failed - check table KPMG_ERROR_CHECK for details.."
    exit 1
    else
    # Load finished OK, if input data file exists, move and rename it
    echo " "
    echo "**** `date +%H:%M:%S` - TEMPLOYEE_DTLS has finished OK.."
    fiThis is the entire SUTEMPCHK.sql script that the UNIX script uses..
    -- Check if any errors have occurred
    SELECT count(1) FROM kpmg_error_check WHERE concurrent_id = &1
    EXITIs it that the above is always returning '1' and so always thinks theres an entry in the errors table?
    Is there an easier way?
    many thanks,
    Steven

    Hi,
    You have to iterate through all pages.marginPreferences:
    var
      myDocument = app.activeDocument,
      allPagesMaPref = myDocument.pages.everyItem().marginPreferences,
      curPageMaPref;
    while ( curPageMaPref = allPagesMaPref.pop() )
      with (curPageMaPref) {
      columnCount = 1;
      //columnGutter can be a number or a measurement string.
      columnGutter = "0";
      bottom = "0"
      //When document.documentPreferences.facingPages == true,
      //"left" means inside; "right" means outside.
      left = "40"
      right = "0"
      top = "0"
      inside = "0"
    Jarek

  • Unix script and sqlplus statements

    I have a unix file which contains sql statements. Included is the sqlplus statement to log on to the database with the username and password: xxxxx/xxxxxx@sid<<EOF
    When I run the unix file from my command line outside of sql, it runs successfully. When I attempt to run the same file in a cron job, I receive the message, sqlplus: not found.
    How can I run this unix file in a cron job? Is something else needed?
    Thank you,
    GD

    When I log to unix with the root password and issue:
    01 9 23 4 3 su - xx -c ". /home/xx/.profile;/home/xx/test.sh"
    The test.sh script executes successfully.
    When I log on with my userid and put the line in a crontab, I receive the following:
    Your "cron" job on yyy1
    su - xx -c ". /home/xx/.profile;/home/xx/test.sh"
    produced the following output:
    su: Sorry
    If cron is run by ROOT, shouldn't I get the same results?
    GD

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

Maybe you are looking for

  • Nokia 5800 31.0.008 CALL BUG

    Hi! Also with this firmware, occasionally, phone crash (freeze and reboot) during a call, when H3G netwok (3 Italy) is missed (0 antenna signal). In Italy, when H3G network (HSDPA, UMTS) is unavailable, the operator switch automatically in roaming mo

  • Problem of using Run-chart in displaying result history of QM

    Hello all, I met a problem about the using of Run-chart in displaying result history of QM, normally, when you use this button to do a statistical chart for checking, the data would be displayed in the measure unit of Inspection Lot. What I want to k

  • Dreamweaver CS3 under Mavericks

    I just upgraded my Mac OS from 10.6.8 (Snow Leopard) to 10.9.4 (Mavericks). My copy of Dreamweaver CS3 no longer works. The error message reads: "You can't open the application Dreamweaver because Power PC applications are no longer supported." The A

  • Cannot uninstall Business Objects 6.5 SP2

    I'm going through the Windows Add or Remove Programs and selecting Business Objects 6.5 SP2.  First off I get a dialog box to "Install or remove fixes"?! with 2 radio buttons "Install Fixes" and "Remove Fixes".  Only "Install Fixes" is enabled, so I

  • PSE 11 crashes in Windows

    I have Adobe Photoshop Elements 11.  I just installed it and it can't load up without crashing.  It always gets to the "Loading Workspace screen" and then this error happens Problem Event Name: APPCRASH   Application Name: PhotoshopElementsEditor.exe