Home » SQL & PL/SQL » SQL & PL/SQL » Problem executing UNIX commands from PL/SQL
icon11.gif  Problem executing UNIX commands from PL/SQL [message #253781] Tue, 24 July 2007 16:22 Go to next message
Messages: 2
Registered: July 2007
Location: UK
Junior Member
I'm having a problem executing UNIX commands from within a PL/SQL procedure. I've coded a Java class using the Runtime.getRuntime().exec method that allows me to pass commands to the UNIX OS, in my particular example, I'm calling a UNIX shell script. I'm aware that the UNIX user when issuing commands this way will be oracle and not my own user-id. The problem I've got is that I'm having to code all commands using their absolute path otherwise I get a 127 RC (UNIX Command not found), e.g. to cat two files together the command I've got to pass is '/usr/bin/cat file1 file2 > fileout' as opposed to 'cat file1 file2 > fileout' as you would type at the command line. Whilst this is not a big problem for single commands, the shell script I'm calling calls other shell scripts that also have UNIX commands in and it's too big a job to change all commands to have absolute path names.

The problem I believe lies with the PATH environment variable. I've echoed this out to a file for the oracle user and the PATH is empty. I've tried setting the PATH in the shell script I'm calling, but this does not make any difference, e.g.

PATH=$PATH:/usr/bin export PATH

passing a command of 'cat file1 file2 > fileout' still generates a 127 RC. The shell script I'm calling does contain the #!/bin/ksh shell pointer at the top.

Any ideas how I can resolve the problem



Re: Problem executing UNIX commands from PL/SQL [message #253782 is a reply to message #253781] Tue, 24 July 2007 16:26 Go to previous messageGo to next message
Messages: 24960
Registered: January 2009
Location: SoCal
Senior Member
You are on the right PATH.
>PATH=$PATH:/usr/bin export PATH

PATH=$PATH:/usr/bin ; export PATH
#line above might give better results - note additional semicolon
Re: Problem executing UNIX commands from PL/SQL [message #253793 is a reply to message #253782] Tue, 24 July 2007 17:50 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member


In 10g it's probably easier to just use dbms_scheduler. You still need to set the path though. Try something like ... /my_path/set_env; /my_other_path/my_cmd...
Previous Topic: Select statement with group by
Next Topic: oracle plsql...keyword that hints nothing should be done, and exit
Goto Forum:

Current Time: Mon Oct 24 09:59:35 CDT 2016

Total time taken to generate the page: 0.13075 seconds