Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to execute UNIX commands from a oracle procedure

Nag AswadhatiOct 21 2013 — edited Oct 21 2013

Hi Experts,

  

     I am writing a shell script into the oracle directory through PL/SQL.

To execute that I need to give the UNIX command chmod +x schellscript.sh

How to execute UNIX command from PL/SQL.

version

------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

SET SERVEROUTPUT ON;

DECLARE

  script_file       varchar2(40) := 'my-temp-script.sh';

  script_data       varchar2(4000);

  MyFile            utl_file.file_type;

  d                 varchar2(4000);

 

begin

    -- Open file

  MyFile := utl_file.fopen('UPNCOMMON_DIR',script_file,'w');

 

  -- Write data to file

  script_data := '#!/bin/bash' || chr(10) || '. /etc/profile' || chr(10)|| 'echo "hello world"';

  utl_file.put_line(MyFile, script_data, FALSE);

  -- Close file

  utl_file.fflush(MyFile);

  utl_file.fclose(MyFile);

  dbms_scheduler.create_job(

    job_name   => 'TEST_shl',

    job_type   => 'EXECUTABLE',

    job_action => '/home/upncommn/',

    number_of_arguments => 2,

    start_date => SYSTIMESTAMP,

    enabled    => FALSE,

    credential_name => 'NEWOS',

    auto_drop  => FALSE);

  dbms_scheduler.set_job_argument_value('TEST_shl', 1, '/workfile/'||script_file);

  dbms_scheduler.set_job_argument_value ('"TEST_shl"', 1, 'chmod +x testingscript.sh');

  dbms_scheduler.enable('TEST_shl');

EXCEPTION

  WHEN OTHERS THEN

   dbms_output.put_line(sqlerrm);

END;

/

Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2013
Added on Oct 21 2013
3 comments
1,450 views