Executing operating system command within trigger or procedure

Hello
Can some one help me out as how to execute operating system command (unix or windows ex.. stop,start,cc,del or copy etc...) in a trigger or procedure.
My requirement is, if some predefined error occure then listener listener should be stopped automatically.
Thanks in advance
kvss

Here is some code to tell you how to do:
First a small Java program that taker a string as a parameter and executes it as an os-command
import java.lang.Runtime;
import java.lang.Process;
public class Commands extends Object {
* Constructor
public Commands() {
// On NT the command should be like this "cmd /c del c:\temp\readme.txt"
// exec execute('cmd /c del c:\temp\readme.txt');
public static void execute (String cmd ) {
try {
Process p = Runtime.getRuntime().exec(cmd);
try {
p.waitFor();
catch (java.lang.InterruptedException intex ) {
intex.printStackTrace();
System.out.println("Return = "+ p.exitValue());
System.out.println(" Done ...");
catch ( java.io.IOException iox) {
iox.printStackTrace();
===================end of java ====
Use loadjava to load it into the database and create a pl/sql wrapper around the java code.
See the manual about loadjava details.
Log in to sqlplus as SYSTEM and create a role for this purpose e.g. 'JAVA_ROLE'
and exec the following as SYSTEM or SYS to make sure the user has the the needed privs.
dbms_java.grant_permission('JAVA_ROLE','SYS:java.io.FilePermission','<<ALL FILES>>','read,write,execute,delete');
dbms_java.grant_permission('JAVA_ROLE','SYS:java.lang.RuntimePermission','writeFileDescriptor',null);
dbms_java.grant_permission('JAVA_ROLE','SYS:java.lang.RuntimePermission','readFileDescriptor',null);
and you're done.

Similar Messages

  • How to execute Operating System commands from Stored procedure.

    Any help on how to execute Operating System commands from stored procedures will be appreciated.
    Nanditha.

    Search the forums for 'External Procedure' and you will find example code that has been posted before.

  • Vista: use the windows program manager to execute operating system commands

    attempting to run forms 6 on vista... the forms app attempts a call sqlplus using the host builtin to populate some tables before calling the report.
    in windows vista i get a message box indicating "use the windows program manager to execute operating system commands".
    is this windwos vista message? would this have to do with permissions?
    any insight most appreciated and thanks in advance.

    I don't know about the HOST-problem, but..
    the forms app attempts a call sqlplus using the host builtin to populate some tables before calling the report.What about putting the logic from the SQL*Plus-scripts into a database-procedure and call that instead. I think,, with the current approach you will get problems at least when you have to migrate to Web (e.g. Forms 10g).

  • How to: execute operating system commands from PL/SQL

    System: IBM pSeries AIX
    Oracle: 11g Enterprise
    Is there a quick way to execute operating system commands from PL/SQL?
    Without creating a JAVA class....
    I need to execute a Loader script.
    I want to do this from within PL/SQL.
    I need to to do 4 things.
    Three require SQL scripts.
    The fourth is SQL*Loader.
    The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
    Is there way to do all this from within ONE PL/SQL SCRIPT ??
    Just let me know.

    Is there a quick way to execute operating system commands from PL/SQL?
    NO
    Without creating a JAVA class....
    I need to execute a Loader script.
    I want to do this from within PL/SQL.
    WHY ON EARTH, such action will create a new connection and become a resource hog?
    I need to to do 4 things.
    Three require SQL scripts.
    The fourth is SQL*Loader.
    The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
    Which is perfect for the purpose.
    Is there way to do all this from within ONE PL/SQL SCRIPT ??
    Just let me know.
    NO, there is NOT. Nor should there be. Why create unstable ineffcient Mickey Mouse systems, glued together by hacking?
    Sybrand Bakker
    Senior Oracle DBA

  • How to execute operation system commands by using TSQL without enabling xp_cmdshell.

    Hi Experts
    Looking for advise if one can use operation system commands using TSQL without enabling xp_cmdshell. 
    actually using xp_cmdshell requires sysadmin privs which I am unable to provide (directly or using proc) to a user  but the user needs some operating system commands to execute for file manipulation from sql server session. Please share your thought.
    Best Regards 
    khalil

    >but the user needs some operating system commands to execute for file manipulation from sql server session
    See article here
    http://www.mssqltips.com/sqlservertip/2014/replace-xpcmdshell-command-line-use-with-sql-server-agent/:
    "Problem
    I need to run something from the command-line, but based on best practices xp_cmdshell has been disabled. The task that needs to run is an internal process that will originate from within SQL Server. Is there a way to do this without using xp_cmdshell?
    Solution
    The use of xp_cmdshell is generally frowned upon and is now recommended to be disabled, unless it is absolutely necessary.  There is a solution that works around this restriction via the use of SQL Server Agent.
    Wherever SQL Server is installed, SQL Server Agent is installed with it (except for SQL Express). SQL Server Agent has the ability to run job steps which invoke the command shell. And in the case that the job is owned by a member of the sysadmin fixed server
    role, the job will execute as the service account under which the SQL Server Agent is running. "
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Executing Operating system commands in ABAP

    Hi
    I want to execute a unix operating system command in an ABAP program. I remember seeing code which executes an operating system command. Could any please let me know about that code?
    Thank You.
    Eswar

    Hi,
    you can try something like this.
    data:cmd(254) type c.
    data: RESULT(255) OCCURS 100 WITH HEADER LINE.
                cmd = 'ls'.
    ** Execute command
      REFRESH RESULT.
      CALL 'SYSTEM' ID 'COMMAND' FIELD CMD
                    ID 'TAB'     FIELD RESULT-*SYS*.
    Kostas

  • Executing Operating system command

    I have a file(ftp)-xi-file(ftp) scenario. I want to run a operating system command on output/processed file which is on a different physical server through a script. But I have seen my script is not working. But when I did the same on the same physical server on which XI is hosted it is working fine. Could you plz somebody advise whether it works ?? if it is the case what precaustions should we take ??
    thanks
    kumar

    Hi Palnati
    OS command will run on XI OS only so you need to use FTP parameter in the script and "permanent connection" as connection mode
    Check this thread also
    Re: FTP ReceiverChannel and OS commands help
    Thanks
    Gaurav

  • Executing Operating system commands

    Hi,
    I need to execute sql*loader from APEX(sqlldr scott/tiger CONTROL=ulcas1.ctl ). How can I implement this in APEX. In oracle forms , I can execute this by a trigger when-button-pressed in a push button - host('sqlldr scott/tiger CONTROL=ulcas1.ctl ').
    Regards
    JIJU

    I took the mention of the Forms method to indicate that the requirement was another manifestation of that currently popular meme Calling calc.exe from APEX
    (At least I've thought there was a lot of it about at the moment...)
    @Jiju - there is no equivalent of host in ApEx. You can write your application to allow files to be uploaded to the server and parsed by your application, or written to the server file system and read as an external table. There are a lot of threads about this kind of thing in this forum: search for "file upload"...

  • Re: Operating System Commands

    Hi All,
    Can any one suggest me how to Execute Operating System Commands from ABAP Environment( i.e from ABAP Editor).
    Thanks & Regards,
    Jayarama Krishna M.

    Hi,
      Check
    https://forums.sdn.sap.com/click.jspa?searchID=11589075&messageID=3391825
    https://forums.sdn.sap.com/click.jspa?searchID=11589075&messageID=3442178
    Regards
    Kiran Sure

  • Exeecuting Operating System Commands in Weblogic

    Hi,
    as part of an offline process every time my database gets updated
    I have to call a tool ( Verity ) to create a collection. This is done
    from a Servlet where the Administrator simply clicks on a link and the
    verity collection is built and updated. Hence, whenever the database
    changes I need to call a system command 'mkvdk' to build a collection
    ( a flat file ).
    My servlet is running in Weblogic 4.5. Is it possible to
    execute operating system commands in java running in weblogic ? I know
    it is possible in java using
    Process runProcess =
    Runtime.getRuntime().exec(systemcommand);
    is it possible under weblogic ? because I have tried it and I get an
    I/O error .....
    Thanks,
    Gavin

    Hi.
    Please post the error you are seeing. Also, what JDK version are you
    running, and OS/platform.
    Thanks,
    Michael
    Gavin wrote:
    Hi,
    as part of an offline process every time my database gets updated
    I have to call a tool ( Verity ) to create a collection. This is done
    from a Servlet where the Administrator simply clicks on a link and the
    verity collection is built and updated. Hence, whenever the database
    changes I need to call a system command 'mkvdk' to build a collection
    ( a flat file ).
    My servlet is running in Weblogic 4.5. Is it possible to
    execute operating system commands in java running in weblogic ? I know
    it is possible in java using
    Process runProcess =
    Runtime.getRuntime().exec(systemcommand);
    is it possible under weblogic ? because I have tried it and I get an
    I/O error .....
    Thanks,
    Gavin--
    Michael Young
    Developer Relations Engineer
    BEA Support

  • Executing a Operating System command from Stored Procedure ??

    I want to execute a Operating System command from a PL/SQL Stored Procedure, can anyone suggest me how can I do this ??
    I am on Sun-Solaris with Oracle 8.1.7 database.
    Please do email me at [email protected]
    Thanks in Advance,
    Ramesh L.

    Are you using a webserver? If so, you could make your operating system script into a CGI program, then execute it from pl/sql using utl_http.request.

  • How to call Operating System commands / external programs from within APEX

    Hi,
    Can someone please suggest how to call Operating Systems commands / external programs from within APEX?
    E.g. say I need to run a SQL script on a particular database. SQL script, database name, userid & password everything is available in a table in Oracle. I want to build a utility in APEX where by when I click a button APEX should run the following
    c:\oracle\bin\sqlplusw.exe userud/password@database @script_name.sql
    Any pointers will be greatly appreciated.
    Thanks & Regards,

    Hi Guys,
    I have reviewed the option of using scheduler and javascript and they do satisfy my requirements PARTIALLY. Any calls to operating system commands through these features will be made on the server where APEX is installed.
    However, here what I am looking at is to call operating systems programs on client machine. For example in my APEX application I have constructed the following strings of commands that needs to be run to execute a change request.
    sqlplusw.exe user/password@database @script1.sql
    sqlplusw.exe user/password@database @script2.sql
    sqlplusw.exe user/password@database @script3.sql
    sqlplusw.exe user/password@database @script4.sql
    What I want is to have a button/link on the APEX screen along with these lines so that when I click that link/button this entire line of command gets executed in the same way it would get executed if I copy and paste this command in the command window of windows.
    Believe me, if I am able to achieve what I intend to do, it is going to save a lot of our DBAs time and effort.
    Any help will be greatly appreciated.
    Thanks & Regards,

  • Re: Error while Execute External Operating System Command using T.code SM49

    Dear Experts,
    I Have uploaded one .exe file in the application server (eg: sum.exe) and created the OS command in SM69 transaction .
    And maintained the application server path in the 'operating system command' field in SM69 t.code.
    Our SAP system, oprating system is UNIX.
    After I have executed the external command using transaction SM49 , but I got the below error.
    Can not execute external program (permission denied) , External program terminated with exit code 1
    Immediately I run the SU53 transaction code to check the authorization, but Authorization was successful.
    Could any one please help on this error.
    Thanks in advance.

    >>Can not execute external program (permission denied) , External program terminated with exit code 1
    You need to give the permission as 755 to your file.
    >>I Have uploaded one .exe file in the application server (eg: sum.exe)
    You are on UNIX and do not expect to any result of .exe file as UNIX doesn't know about this.

  • Execute external operating system command

    Hi Friends,
    I have a requirement to run a script file with extention '.PL' on the application server using ABAP.
    i have sample how to run it in XI.
    XI3.0 provides a very simple way of handling this using the "Operating System Command" in the File Adapter.
    I post my output file in the following folder,
    /usr/sap/sapout/test/
    The shell script is available in the following path,
    /usr/sap/bin/convert.pl
    The figure below explains as to how we call the shell script using "Operating System Command".
    File Acess parameters
          Target Directory      = /usr/sap/sapout/test/
          File Name Scheme = TestOutput.txt
    Processing Parameters
         File Construction Mode          = Add Time Stamp
         File Type                              = Binary
         Operating System Command = /usr/sap/bin/convert.pl %F
    I have to do the same thing in ABAP as it has been done for XI as mentioned in the above example.
    My operating system is UNIX.
    If any one can give me a sample it would be really helpful to me.
    Thanks in advance,
    Arundhathi.

    Hi Arundhati,
    You can run operating system commands from ABAP.
    e.g. If you want to change UNIX right for any file, you can use following code.
    lv_ucomm  = 'chmod a+rwx 123.txt'.
    CALL 'SYSTEM' ID 'COMMAND' FIELD lv_ucomm.
    whatever command you provide in Field parameter ( lv_ucomm in the above case ), ABAP run that command at operating system level.
    In your case, you can provide command in lv_ucomm to run script at operating system level.
    Hope it will help you.
    Regards,
    Naren

  • How does client invoke an operating system command in the Server machine.?

    Guys,
    Is there any way that a client could trigger an operating system command on the Oracle Server machine?
    I've a VB scipt file in the server machine.My requirement is to execute that VB file on the server machine.(The script would essentially create a DSN on the server machine).
    The normal way to execute a VB script would be to specify the name of the file in the command prompt.(If my VB script ONDEMAND.VBS resides in C:\ONDEMAND folder,I need to execute the statement
    "C:\ONDEMAND\ONDEMAND.VBS" in the command prompt to get it executed.)
    I would utilise the SQL command below
    HOST C:\ONDEMAND\ONDEMAND.VBS
    to invoke it programatically(from a PL\SQL scipt).
    Can someone help me in utiliting HOST command in Oracle(Or by any other means) for a client database operation to execute an Operating system command in the Oracle server machine?
    Thanks,
    Bhagat

    Hi Bhagat,
    This has been asked several times recently:
    Executing Shell Script from PL/SQL Block
    Fire an executable using oracle
    Cheers,
    Colin

Maybe you are looking for

  • Dynamic images in PDF (Adobe interactive form)

    Hi All,         I have stored image in database using BLOB. I retrieve the image using      WDWebResourceType.getWebResourceTypeForFileExtension(extn);//get Type      IWDResource res = WDResourceFactory.createCachedResource(CSVFile, Filename, type1,t

  • How to close a video after it plays

    Hey people, Say you have a video intro that you would like to have dissapear after it plays. Use this code. (place in trigger event) var vid = sym.$("bird_holder"); vid.html('<video width="1022" height="575" id="bird" src="video/Intro_Animation.mp4"

  • Bb 9320 showing error 102 on updating

    hi mu phone shows the following errors  when i took the event log  verifyHash1 failed for net_rim_bb_medialoader_toolkit_320x240_Armstrong_01-65(4467) : hash (codfile)0 40 5a e9 59 ff f3 b8 76 ac 1d 28 69 28 a2 ed d5 8b 7b 57 fb : hash (mod_info)1 41

  • Log out 'button' in Yahoo mail is not active/clickable in Firefox

    In Yahoo mail the logout 'button' is not active when using Firefox (currently 3.6.8) (&running on XP) so the onlyb way to Logout is to close the browser ( works fine on same Laptop with IE)

  • SMS via iChatav?

    Hi, Is there any app/plugin which will send sms via ichat to UK mobile phones? I know it's possible to do that in US. Or perhaps some handy widget which will do that instead? Thanks Peter