12c Shell to Linux

oracleoracle-12cplsql

I am replacing two Oracle 11g servers with 12c

TL/DR – when shelling out to a run an O.S. file, the PATH environmental variable is not being set.

On the old servers we use an external library to allow executing commands from the shell. This same shell was set up on the new 12c servers.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void sh(char *command) {
  int num;
  num = system(command);
}

A library was created and a procedure set to call it.

CREATE OR REPLACE PROCEDURE DBUTILITIES.shell(cmd IN char)
AS EXTERNAL
   NAME "sh"
   LIBRARY shell_lib
   LANGUAGE C
   PARAMETERS (cmd string);
/

Everything works great – except that we lose the PATH environment variable when going to the shell. All the other environment variables are still there, just PATH is reset as blank. This means that even to run something as simple as 'ls' or 'cp' you have to use the full path of '/bin/ls' or '/bin/cp'

I ran the following to see what variables were being set:

execute dbutilities.shell('/usr/bin/printenv > /tmp/envvariables.txt');

A snippet of the results show that PATH has been reset to nothing. (Note that even custom environmental variables such as email notifications are still set in this file). Also, when connecting in via ssh the path is set correctly for this user. It is only when dropping to a shell from Oracle that we have this issue.

~~~
ORACLE_BASE=/home/oracle
KDEDIR=/usr
PATH=
MAIL=/var/spool/mail/oracle1
~~~~

I am getting the same issue on both servers. Has anyone run across this? Any suggestions on a fix?

Best Answer

If you're on at least 11g, the method is deprecated, as DBMS_SCHEDULER functionality is capable of calling a shell script or C program.

However, if you really want to do it this way, you can set ENVS in the definition of the SID_LIST_your_external_proc_listener_name.

See MOS Doc ID 99136.1 for more details.

Hope that helps.