How to run OS commands from PL/SQL???
Hi
Is there any way to run OS commands(Windows Platform) from within PL/SQL?
Thanks
APC,
I am working on Discoverer, having lots of BAs & Workbooks created & stored in Database. Now if i want to move all the workbooks from one place to another (like from development to test or production) i can use Command line interface of Disco to do this. But i don't see any option there to export all the workbooks, so i thought of writing a pl/sql to get all the workbook names from the EUL then fire export Command for each record(although not a good practice but its a one time work). This is the place where i need to run OS command from within PL/SQL. Although it doesn't seem possible now(as you all said) without external procedure.
Lastly, you are right that "Oracle make databases not operating systems" but my first impression/comment about oracle is:
"Oracle is far Bigger, Powerful, Complex, Vast and Interesting System than any other..." so i believe it can do/capable doing anything :-)
thx Ashutosh,
Host is definitely an option but i can't run it from pl/sql(that i am looking for)..
Similar Messages
-
Running sqlldr command from PL/SQL Block
DECLARE
BEGIN
END;In SQL * plus we can run DOS commands using the following command
HOST DIR
HOST DIR/P
But When we can't run the HOST command in PL/SQL Block..
I have to Run sqlldr command from PL/SQL Block..
i tried as follows
DECLARE
BEGIN
EXECUTE IMMEDIATE ' host sqlldr control= bad= ';
END;
By
BalaNagaRaju -
Run OS command from Pl/SQL
Is there any way to execute an OS command from pl/sql other than using dbms_pipe & pro*C combo. I have done this way before but it seems there is built-in oracle package which can do this in 8/8i.
Also HOST command in forms will execute the OS coomand from the clinet. Is there any way to execute the OS command on the server from the forms clinet?
thanks,
Ravi.
nullRavi,
Can you send me an example how one can
execute a this command from a PL/SQL
program 'sed 3q /etc/passwd'.
Please write to me at
[email protected]
thanks
Pramod -
How to run system commands from JAVA
Hi Friends,
How to run windows system commands from JAVA
Runtime r=Runtime.getRuntime();
r.exec("dir");
Throwing following Exception
CreateProcess :dir error=2
Thanks in advance
HamsaHi ,
in Windows NT this is not possible, you can use the following :
Runtime r=Runtime.getRuntime();
StringBuffer sbuf = new StringBuffer();
String dir = new String();
java.lang.Process proc = r.exec("cmd /c dir");
InputStream is = proc.getInputStream();
int ch ;
while((ch=is.read() ) != -1)
sbuf.append((char)ch);
is.close();
dir = sbuf.toString();
System.out.println(dir ); -
Running linux commands from pl/sql
Hi, I'm using a java class to run os commands but it doesn't work, i think it's permissions but i cant understand why.
the java class is the following:
import java.io.*;
import java.lang.*;
public class RunCmd extends Object{
public static int RunThis(String args){
Runtime rt = Runtime.getRuntime();
int rc = -1;
try{
Process p = rt.exec(args);
int bufSize = 4096;
BufferedInputStream bis =
new BufferedInputStream(p.getInputStream(), bufSize);
int len;
byte buffer[] = new byte[bufSize];
while ((len = bis.read(buffer, 0, bufSize)) != -1)
System.out.write(buffer, 0, len);
rc = p.waitFor();
catch (Exception e)
e.printStackTrace();
rc = -1;
finally
return rc;
the pl/sql function i created:
function run_cmd(p_cmd in varchar2) return number as language java name 'RunCmd.RunThis(java.lang.String) return oracle.sql.NUMBER';
i gave the following permissions:
begin
dbms_java.grant_permission(user, 'SYS:java.io.FilePermission', '/home/mails/*', 'execute');
dbms_java.grant_permission(user, 'SYS:java.io.FilePermission', '/home/mails/*', 'write');
dbms_java.grant_permission(user, 'SYS:java.io.FilePermission', '/home/mails/*', 'read');
dbms_java.grant_permission(user, 'SYS:java.io.FilePermission', '/home/mails/*', 'delete');
dbms_java.grant_permission(user, 'SYS:java.lang.RuntimePermission', '*', 'readFileDescriptor');
dbms_java.grant_permission(user, 'SYS:java.lang.RuntimePermission', '*', 'writeFileDescriptor');
Dbms_Java.grant_Permission(user, 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
Dbms_Java.grant_Permission(user, 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
dbms_java.grant_permission(user, 'java.io.FilePermission', '/home/mails/*', 'execute');
dbms_java.grant_permission(user, 'java.io.FilePermission', '/home/mails/*', 'write');
dbms_java.grant_permission(user, 'java.io.FilePermission', '/home/mails/*', 'read');
dbms_java.grant_permission(user, 'java.io.FilePermission', '/home/mails/*', 'delete');
dbms_java.grant_permission(user, 'java.lang.RuntimePermission', '*', 'readFileDescriptor');
dbms_java.grant_permission(user, 'java.lang.RuntimePermission', '*', 'writeFileDescriptor' );
Dbms_Java.grant_Permission(user, 'java.lang.RuntimePermission', 'readFileDescriptor', '');
Dbms_Java.grant_Permission(user, 'java.lang.RuntimePermission', 'writeFileDescriptor', '');
commit;
end;
The command i'm trying to execute is:
select run_cmd('/bin/sh -c "ls -ltr /home/mails> /home/mails/teste.txt"') from dual;
i gave chmod 777 /home/mails and i already run this command directly in console mode and works just fine, so i dont think it's permissions related to the user oracle.
when i run
select run_cmd('/bin/sh -c "ls -ltr /home/mails> /home/mails/teste.txt"') from dual;
it returns 2
if i run
select run_cmd('/bin/sh -c ls -ltr /home/mails> /home/mails/teste.txt') from dual;
it returns 127
if i run just
select run_cmd('ls -ltr /home/mails> /home/mails/teste.txt') from dual;
it returns -1
if anyone as any clue please, i'm trying to solve this problem for 2 days and i don't have any clue for the solution...when i remove the /bin/sh -c it returns -1
i think that it runs the command because there is a diference in the return value from a valid command a an invalid, for example:
if i run a valid command
select k_cs_controlo.run_cmd('/bin/sh -c "ls -ltr /home/mails > /home/mails/teste.txt"') from dual;
it retuns 2
if i run an invalid command(removed the " between the ls command)
select k_cs_controlo.run_cmd('/bin/sh -c ls -ltr /home/mails > /home/mails/teste.txt') from dual
it returns 127
thanks for the replies Sven -
How to run unix command from Oracle Foms 10g
OS: UNIX Solaries, Oracle Application Server 10g
To run shell script from Oracle Forms, I used the following host('/bin/bash /u01/compile.sh') and it works well
Now, I need to run unix command something like
host('mv form1.fmx FORM1.FMX') but it's not working
I tried to append the command "mv form1.fmx FORM1.FMX" to the compile.sh shell script but also it's not working although the rest lines of the shell script is running well
Edited by: slamonty on Aug 23, 2012 12:36 AMYes, Thank you so much, it works well as follow
$ /bin/mv /u01/oracle/runtime/test/form1.fmx /u01/oracle/runtime/test/FORM1.FMX Edited by: slamonty on Aug 23, 2012 9:59 AM
Edited by: slamonty on Aug 23, 2012 11:14 AM -
Running OS command from PL/SQL
Hi All,
Is there any way of running a Operating System command thru the PL/SQL Procedure. I am using oracle on the Unix Platform. Do help me.
Thanks In advance,
Nitin JainAs one who did it, here's what I recommend.
declare
cmdstr varchar2(200); -- this is to compose the OS command to run
begin
-- then you should have something like this
cmdstr:=...;
cmdstr:=cmdstr| |...;
host(cmdstr); -- this actually runs the command held in the cmdstr varchar
end;
Beware: you must be certain which OS you have to deal with, for some procs may be run on UNIX machines as well as on WINDOZE! -
hi,
is any one able to resolve my problem.
thanks in advance
my problem is that i want to run os command (dir/b to get list of all files and directory names) using oracle 10.1.0.1.0 plsql.
what will be the code snippet in oracle plsql.
if any one have an idea then please let me know.
thanks.First bullet of the thread no one reads
Posters, please mind these common-sense rules when participating here:
- When asking a question, provide all the details that someone would need to answer it. Consulting documentation first is highly recommended.
For me that includes perusing available resources. The 'Search Forum' button of this forum is. Http://asktom.oracle.com also is. Ninety nine percent of all users posting here did zero to resolve their own problem. This is why the results of 'Search Forum' are such a mess. As Oracle does nothing to moderate or clean up this forum, the mess stays and is aggravated because most people....
etc.
But then consilodating threads in a series of FAQs wouldn't help, as most people wouldn't read them.
Sybrand Bakker
Senior Oracle DBA -
Running OS Command from PL/SQL: ORA-29532
Hello All,
I have created a java program, loaded into database using loadjava utility and finally gave grant on execute to public. Then made a wrapper function to call it inside as below:
FUNCTION fn_OSCommand_Execute (command IN STRING)
RETURN NUMBER
IS
LANGUAGE JAVA
NAME 'OSCommand.Execute(java.lang.String) return java.lang.int';
Logged into SYS and gave the following gants to SCOTT using dbms_java
declare
v_key NUMBER;
begin
DBMS_JAVA.GRANT_PERMISSION('SCOTT', 'SYS:java.io.FilePermission', '<<ALL_FILES>>', 'read,write,execute,delete',v_key);
DBMS_JAVA.GRANT_PERMISSION('SCOTT', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '',v_key);
DBMS_JAVA.GRANT_PERMISSION('SCOTT', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '',v_key);
dbms_java.grant_permission( 'SCOTT', 'SYS:java.io.FilePermission', 'c:\windows\system32\cmd.exe', 'execute',v_key);
COMMIT;
end;
When I am calling the function, I am getting the below error:
ORA-29532: Java call terminated by uncaught Java exception: java.security.AccessControlException: the Permission (java.io.FilePermission c:\windows\system32\cmd.exe execute) has not been granted to SCOTT. The PL/SQL to grant this is dbms_java.grant_permission( 'SCOTT', 'SYS:java.io.FilePermission', 'c:\windows\system32\cmd.exe', 'execute' )
I am running on Windows7 Platform & Oracle 12c 64bit version.
Waiting for all of your expert advice.Yes my Oracle server is installed on Windows 7.
Actually the user (SCOTT) was missing soome Network ACLs. I got it resolved by giving the connect, resolve network acls for the required host as below:
BEGIN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL(acl => 'dbserver.xml',
description => 'DB Server ACL',
principal => 'SCOTT',
is_grant => true,
privilege => 'connect');
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(acl => 'dbserver.xml',
principal => 'SCOTT',
is_grant => true,
privilege => 'resolve');
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL(acl => 'dbserver.xml',
host => 'xxxxxxxxxxxx');
END;
COMMIT; -
How do run dos command from form
Hi all,
I need to run a file.bat (dos), someone can help me, please?
I know the command HOST(..), but when execute the command exit a black window. Are there other command?
Thank you
SilviaHello,
I know the command HOST(..), but when execute the command exit a black window. Are there other command?Version Dependent.
For less then or equal 6i version
HOST('CMD /C C:\batch_file_name.bat');For the web based...
The same above command will work for AS level. If you need on client side then
CLIENT_HOST('CMD /C C:\batch_file_name.bat');-Ammad -
Is it possible to run host command from SAP environment? How do you run?
Hi
Is it possible to run host command from SAP environment? How do you run?
Thank YouHello Subhash
You will more details in the following thread:
Re: How to define command for SXPG_COMMAND_EXECUTE
Regards
Uwe -
How to: execute operating system commands from PL/SQL
System: IBM pSeries AIX
Oracle: 11g Enterprise
Is there a quick way to execute operating system commands from PL/SQL?
Without creating a JAVA class....
I need to execute a Loader script.
I want to do this from within PL/SQL.
I need to to do 4 things.
Three require SQL scripts.
The fourth is SQL*Loader.
The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
Is there way to do all this from within ONE PL/SQL SCRIPT ??
Just let me know.Is there a quick way to execute operating system commands from PL/SQL?
NO
Without creating a JAVA class....
I need to execute a Loader script.
I want to do this from within PL/SQL.
WHY ON EARTH, such action will create a new connection and become a resource hog?
I need to to do 4 things.
Three require SQL scripts.
The fourth is SQL*Loader.
The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
Which is perfect for the purpose.
Is there way to do all this from within ONE PL/SQL SCRIPT ??
Just let me know.
NO, there is NOT. Nor should there be. Why create unstable ineffcient Mickey Mouse systems, glued together by hacking?
Sybrand Bakker
Senior Oracle DBA -
O/s commands from PL/SQL
hi all..
i want to execute operating system commands from PL/SQL..
particulary imp command....
i have used the f/wg approach but while i execute the imp command it does not responds me any output..
I have to kill the process from o/s.
prodn is my user
--AS SYS user
begin
dbms_java.grant_permission( 'PRODN',
'SYS:java.io.FilePermission',
'/oracle/product/9.2.0/bin/imp',
'execute' );
dbms_java.grant_permission
('PRODN',
'java.lang.RuntimePermission',
'writeFileDescriptor' );
end;
---------------------------------AS PRODN user
create or replace and compile
java source named "Util"
as
import java.io.*;
import java.lang.*;
public class Util extends Object
public static int RunThis(String args)
Runtime rt = Runtime.getRuntime();
int rc = -1;
try
Process p = rt.exec(args);
int bufSize = 4096;
BufferedInputStream bis = new BufferedInputStream(p.getInputStream(),
bufSize);
int len;
byte buffer[] = new byte[bufSize];
// Echo back what the program spit out
while ((len = bis.read(buffer, 0, bufSize)) != -1)
System.out.write(buffer, 0, len);
rc = p.waitFor();
catch (Exception e)
e.printStackTrace();
rc = -1;
finally
return rc;
create or replace
function RUN_CMD(p_cmd in varchar2) return number
as
language java
name 'Util.RunThis(java.lang.String) return integer';
create or replace procedure RC(p_cmd in varchar2)
as
x number;
begin
x := run_cmd(p_cmd);
end;
i executed the command as follows in sql>
BEGIN
rc('/oracle/product/9.2.0/bin/imp tim/tim file=/home/oracle/vas4359.dmp log
=log1.log');
END;
it runs fine creates log1.log in / home/oracle but there is no output in
log1.log file.
I have to kill the process as follows after which sql> displays me :
"PL/SQL procedure successfully completed."
[oracle@msebdb oracle]$ ps aux|grep imp
oracle 20052 0.0 0.2 12732 4328 ? S 11:57 0:00 /oracle/product/
.2.0/bin/imp file=/home/oracle/vas4359.dmp log=log1.log
oracle 20102 0.0 0.0 3692 652 pts/2 S 12:03 0:00 grep imp
Note:There is no tim user.. i just want to get error in my log file..
my further steps are to read this log file and send email/notifications to users.
my main program is as f/ws:
/*imp and check log file*/
create or replace procedure abc
as
v_exists boolean;
v_exists_log boolean;
ex_open BOOLEAN;
flen NUMBER;
bsize NUMBER;
vInHandle_open utl_file.file_type;
vInHandle_open_log utl_file.file_type;
v_filelog utl_file.file_type;
v_fl utl_file.file_type;
v_pth varchar2(60);
v_fnm varchar2(60);
v_file_exists varchar2(60);
v_logline varchar2(30) ;
v_search varchar2(30) :='ORA-';
vNewLine VARCHAR2(32767);
cursor c_fname is
select full_pth ,f_name from upld_file_t where f_name in
(select f_name from tbl_file_nm where typ_file='D' AND DEL_FLG='N');
BEGIN
for v_sec in c_fname
loop
utl_file.fgetattr(LOCATION=>'ORALOAD',
FILENAME=>v_sec.f_name,
FEXISTS=>v_exists,
FILE_LENGTH=> flen,
BLOCK_SIZE=>bsize);
if v_exists
THEN
dbms_output.put_line('File Exists' || v_sec.f_name);
v_file_exists:=v_sec.f_name;
--dbms_output.put_line('v_file_exists ' || v_file_exists);
dbms_output.put_line('File Length: ' || TO_CHAR(flen));
dbms_output.put_line('Block Size: ' || TO_CHAR(bsize));
dbms_output.put_line(' before file open');
vInHandle_open := utl_file.fopen('ORALOAD',v_sec.f_name,'R',32767);
-- dbms_output.put_line(' after file open');
-- do whater with teh file data
v_fl:=utl_file.fopen('ORALOAD','v_sec.f_name','W');
dbms_output.put_line('v_sec.f_name');
IF utl_file.is_open(vInHandle_open)
THEN
/*if log file exists..*/
utl_file.fgetattr(LOCATION=>'ORALOAD',
FILENAME=>v_sec.f_name||'.log',
FEXISTS=>v_exists_log,
FILE_LENGTH=> flen,
BLOCK_SIZE=>bsize);
if v_exists_log
then
dbms_output.put_line('file' ||v_sec.f_name||'.log');
v_filelog :=utl_file.fopen('ORALOAD',v_sec.f_name||'.log','W',32767);
LOOP
BEGIN
UTL_FILE.PUT(v_filelog,'ORA-');
exit;
END;
END LOOP;
else
dbms_output.put_line('File not found' || v_sec.f_name);
END IF;
UTL_FILE.fclose(v_filelog);
dbms_output.put_line('Closed File ' || v_sec.f_name|| '.log');
END IF;
/*imp THE FILE and read log file*/
utl_file.fgetattr(LOCATION=>'ORALOAD',
FILENAME=>v_sec.f_name||'.log',
FEXISTS=>v_exists_log,
FILE_LENGTH=> flen,
BLOCK_SIZE=>bsize);
if v_exists_log
then
dbms_output.put_line('file' ||v_sec.f_name||'.log');
v_filelog :=utl_file.fopen('ORALOAD',v_sec.f_name||'.log','R',32767);
LOOP
BEGIN
UTL_FILE.get_line(v_filelog,v_logline);
if v_logline = v_search then
dbms_output.put_line(v_logline);
end if;
UTL_FILE.fclose(v_filelog);
dbms_output.put_line('Closed File ' || v_sec.f_name|| '.log');
exit;
END;
END LOOP;
else
dbms_output.put_line('File not found' || v_sec.f_name);
END IF;
END IF;
END LOOP;
--close the curosr .. check this
EXCEPTION
WHEN UTL_FILE.ACCESS_DENIED THEN
DBMS_OUTPUT.PUT_LINE('No Access!!!');
when others then
dbms_output.put_line('ERROR (open_file) => '||sqlcode);
dbms_output.put_line('MSG (open_file) => '||sqlerrm);
end;Hi,
You might have better luck in the PL/SQL or Java forums. They are located here:
PL/SQL: PL/SQL
Java: http://forums.oracle.com/forums/forum.jsp?forum=99
Good luck,
Mark -
Running ssh command from java and then answering password prompt
Hi,
I have a situation that has not solved yet. I am running ssh command from unix terminal without any problem, and then i enter password.
For example :
[oracle@fuata]:/export/home/oracle> ssh -N [email protected] -L 9901:127.0.0.1:9999
Password:
It is working. I have question that how can i perform this in java? I am thinking that i can run ssh command by using Runtime Class, it is ok. But how can i answer the password? I am a bit confused. Is there any example looks like this?
Thanks for responses.futi wrote:
Thanx. Firstly i insisted to do this without jsch but actually this is harder than jsch. I edit some of code pieces PortForwardingL.java and could run it. It works problem-free. Could you say why you "insisted" on this approach. It can't be for speed+ since jsch is very fast. It can't be for portability+ since jsch is portable but the use of Runtime.exec() requires the installation of ssh software. It can't be because of limitations+ since jsch is a fully featured library. It can't be for security+ since jsch is secure. It can't be for ease of use+ since jsch is much easier to use than ssh with Runtime.exec(). Unless it's a licensing issue, it can't be for commercial+ reasons since jsch is free. The only reason I can think of why one would "insisted" on this approach is if it is for some college project. -
Running ls command from Java stroed procedure no output
Hi ,
I am trying to run ls command from java stored procedure in oracle
Process p = Runtime.getRuntime().exec("ls");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("output of the command run:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
from java stored procedure in oracle.
i get output of println statments but it does not go into while loop to print from stdInput.
Result of running Java stored procedure is -
output of the command run:
Call completed.
when i run the program on client side it works fine.
Has anybody tried this from java stroed procedure.
Thanks,
JagJag,
Actually, the question of whether it works for me seems to depend on the version of the OS (or Oracle). On RedHat Linux (Oracle 8.1.6) it didn't work at all, but on Solaris (Oracle 9.0.2) it did. Here's the output from that run:
SQL> /
output of the command run:
init.ora
initDBPart9i.DBPSun01.ora
initdw.ora
lkDBPART9I
orapw
orapwDBPart9i
spfileDBPart9i.ora
Done
PL/SQL procedure successfully completed.
But, I did need to change a line of your code to this:
Process p = Runtime.getRuntime().exec("/usr/bin/ls");
your original was:
Process p = Runtime.getRuntime().exec("ls");
You might consider, if possible, use of some of the Java File classes instead of ls, as this might make things more predictable for you. There were some examples in oramag.com a few months ago, but they were pretty simple (you might not need them).
Hope this helps,
-Dan
http://www.compuware.com/products/devpartner/db/oracle_debug.htm
Debug PL/SQL and Java in the Oracle Database
Maybe you are looking for
-
LOVs not working in Webi Report for SAP BO 4.1 SP 2 Patch 3
Hello , I have developed reports and universes in SAP BO 4.0 SP 5 and i have migrated those reports to higher version of BO which is 4.1 SP2 Patch 3. My universe is working fine with LOVs but when i run the webi report , the LOVs arent working. have
-
Localized string not found & menu will not display in Vista
I have had an issue since late version 3 on my Vista Home Premium PC, when I installed a new copy and started seeing no menu, and the bookmarks and right-clicks respond with "Localized string not found..." I have tried the cleanup in a previous messa
-
iphone 3 refuse to switch off
-
Pacman issue - error: .. : No such file or directory.
It seems I have my first issue, and it's with Pacman. I get this error everytime I sync the database or install a package, even though everything seems to go fine. error: /var/lib/pacman/extra/flite-1.3-2/desc: No such file or directory I don't know
-
HT3978 There is no link to downloadable software on my Account Page.
There's no "downloadable software" link on my account page. How do I download the component? I already bought it. It doesn't show up in my order history because it was over 18 months ago. Very annoyed, how do i get it. Thanks.