Rahul
Rahul

Reputation: 191

Running Shell Script on Different Linux Server using oracle PL/SQL SP

I want to run a shell script placed on Linux server when a stored procedure is called.

The below code works like a charm if the script is placed on the same server where database is installed, say "Linux Server A".

Database Version: Oracle Database 12c Linux Version: Red Hat Linux 7

begin
  dbms_scheduler.create_credential
  (
    credential_name => 'my_credential',
    username        => 'user',
    password        => 'pass'
  );
end;
/
create or replace procedure RunShell
as
begin
  dbms_scheduler.create_job
  (
    job_name             => 'shell_scripts_job',
    job_type             => 'executable',
    number_of_arguments  => 1,
    job_action           => '/usr/bin/sh',
    auto_drop            => true,
    credential_name      => 'my_credential'
  );
  dbms_scheduler.set_job_argument_value(job_name=>'shell_scripts_job', argument_position=>1, argument_value=>'/u01/Script.sh');
  dbms_scheduler.enable('shell_scripts_job');
  dbms_scheduler.run_job(job_name=>'shell_scripts_job');
END;
/
EXECUTE RunShell;

The issue is, my DB is installed on "Linux Server A" and the shell script I want to run is on "Linux Server B".

This script performs some operations which has to be done "Linux Server B". One of the main functions is that it starts/stops another application residing on "Linux Server B".

How can I achieve this ?

Upvotes: 2

Views: 1759

Answers (1)

BriteSponge
BriteSponge

Reputation: 1054

You can create a NFS share on the remote machine and then mount that share on the local machine. That remote directory that is being shared can then be referred to as though it was a local directory.

As an example if you create a share on the remote directory '/u01' and call that share 'remote_scripts' you would mount that at /mnt/remote_scripts.

The argument_value in your code would then be

argument_value=>'/remote_scripts/Script.sh'

There is a fair bit more detail to setting up the share and the permissions need to be thought about but in principle this works.

The following page gives a good rundown of the set-up but get your SYSADMIN involved as they know your network. (https://www.tecmint.com/how-to-setup-nfs-server-in-linux/)

Upvotes: 1

Related Questions