Skip to Main Content
  • Questions
  • Execute Shell Script from Oracle Database Program.

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Pal.

Asked: February 05, 2017 - 7:46 pm UTC

Last updated: February 06, 2017 - 3:08 pm UTC

Version: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

Viewed 1000+ times

You Asked

Hi Experts,

I have done the required setup to execute unix OS commands using Java class as mentioned in the link( https://oracle-base.com/articles/8i/shell-commands-from-plsql ) from database programs , I was able to run echo command from the Pl/SQL program, however for any other executable commands I need prefix /bin eg. to do a ls I need to use the syntax as shown below
<
BEGIN
unix_command('/bin/ls -lrt');
end;
/>

Also some of commands are not working like "tee command" where I am getting the below error.

line 25: tee: No such file or directory

So in this regard I request to help me out to able to execute the script without prefix as /bin and also to allow the usage of tee command.

Thanks.


and Connor said...

I'd recommend either

a) fully qualifying all of your programs, or
b) running a script, and setting the path within it. Then you only need to fully qualify the path to the shell program, eg

/bin/ksh /my/full/path/my_shell_script.sh

We do this for security reasons - otherwise, someone might alter the path and hence pick up their *own* malicious script, which would then run with the permissions of the database account.

Is this answer out of date? If it is, please let us know via a Comment