8 Replies Latest reply: Apr 10, 2013 11:50 PM by Billy~Verreynne RSS

    Run a BAT file on another machine

    k1ng87
      I have a BAT file on another machine that l would like to run at the end of a procedure. The procedure returns two values, either false or true, if the result is true, I would like to run a BAT file on a REMOTE machine. Can I do that via Oracle procedure? Or would I have to run a BAT file on the local oracle machine which would then run the BAT file on a remote machine?
        • 1. Re: Run a BAT file on another machine
          rp0428
          Welcome to the forum!

          Whenever you post provide your 4 digit Oracle version.
          >
          I have a BAT file on another machine that l would like to run at the end of a procedure. The procedure returns two values, either false or true, if the result is true, I would like to run a BAT file on a REMOTE machine. Can I do that via Oracle procedure? Or would I have to run a BAT file on the local oracle machine which would then run the BAT file on a remote machine?
          >
          You can use a scheduler job to execute processes on remote servers.

          Those servers need to have an Oracle agent installed.

          See this example article.
          http://www.oracle-base.com/articles/11g/scheduler-agent-installation-11gr2.php

          The scheduler docs describe it but the info is scattered all over.
          http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_sched.htm
          • 2. Re: Run a BAT file on another machine
            k1ng87
            Thanks for the welcome! Sorry about the version thing, I'm currently using 11.2.0.3
            • 3. Re: Run a BAT file on another machine
              Billy~Verreynne
              user13340968 wrote:
              I have a BAT file on another machine that l would like to run at the end of a procedure. The procedure returns two values, either false or true, if the result is true, I would like to run a BAT file on a REMOTE machine. Can I do that via Oracle procedure? Or would I have to run a BAT file on the local oracle machine which would then run the BAT file on a remote machine?
              What about security considerations? How does the remote machine authenticate the local PL/SQL server process?

              What about network/server failures, where the local PL/SQL server process cannot reach the remote server in order to execute the BAT file? (why not a CMD file?)

              The easiest method to implement this would be a via a web server on the remote machine that provides a URL in order to execute the BAT file as a CGI script. This of course needs proper security to protect that CGI script from being executed by anyone.

              The local PL/SQL server process can then use UTL_HTTP to make a call to the web server to execute the CGI.
              • 4. Re: Run a BAT file on another machine
                k1ng87
                Hi Bill,

                I was thinking about the authentication piece. Not sure how Oracle (windows machine) would log on to the remote machine (also windows) to run the .bat file. Seems like Oracle Agent on the remote machine would be an easier route? Thoughts?
                • 5. Re: Run a BAT file on another machine
                  k1ng87
                  Could you run a Psexec command from oracle?
                  • 6. Re: Run a BAT file on another machine
                    Billy~Verreynne
                    user13340968 wrote:

                    I was thinking about the authentication piece. Not sure how Oracle (windows machine) would log on to the remote machine (also windows) to run the .bat file. Seems like Oracle Agent on the remote machine would be an easier route? Thoughts?
                    NTLM security can be used for network connectivity. But that is clunky and proprietary.

                    As I've already mentioned, the easiest way, using standard protocols and standard security, is to run a web server on the remote server. And via that web server's CGI (Common Gateway Interface), execute the BAT file safely and securely, and get a proper response from the BAT script's execution.
                    Could you run a Psexec command from oracle?
                    Can you execute external programs from Oracle? Yes. 3 methods. Java stored proc that enables o/s command line access. External procedures that allows access to DLLs and executables. DBMS_SCHEDULER that supports running external programs.

                    Whether psexec will work when used (called by) an Oracle server thread, running inside the oracle.exe service - that is another question.
                    • 7. Re: Run a BAT file on another machine
                      k1ng87
                      Hi Bill,

                      The remote server is setup as a webserver but do not no anything about CGI (my programming knowledge is limited to SQL). Would this be something easy for me to script? Did some googling but seems a bit complex.
                      • 8. Re: Run a BAT file on another machine
                        Billy~Verreynne
                        CGIs are not difficult to setup. Though PHP and Perl are more often used than BAT scripts.

                        Setting it up, depends on the web server you have. It should enable you to configure a CGI directory. All executables (including BAT files), in that CGI directory, can be executed via a web browser (assuming proper security).

                        A basic Apache example (for Linux and NT) at http://www.jlk.net/apache/testing_cgi.shtml

                        You can use the following approach for your command shell CGI:
                        @echo off
                        rem CGI wrapper for running my DO_STUFF.BAT script
                        
                        rem We tell the web browser to expect plain text output
                        echo.Content-type: text/plain 
                        echo.
                        
                        rem We now call our BAT script
                        c:\where_ever\do_stuff.bat
                        
                        rem End-of-CGI
                        The critical thing is protecting the CGI URL against unauthorised access - again, your web server will provide that functionality and its documentation will have the details.

                        Please note that this is pretty much off-topic stuff in this forum. If you have more web server or CGI questions, I suggest asking them in a support forum for the specific web server product used.