oracle中執行os命令(轉)
I can think of a couple of different ways....
o In Oracle8i, release 8.1, we could use java to run a system command with an "&" after it (assuming unix) or perhaps "start xxx.cmd" if using NT.
o In Oracle8.0 and up, we can write an external procedure in C that runs host commands with system() and the "&". (see attached for an external procedure example)
o In Oracle7.0 and up, we can use dbms_pipes to talk to a daemon running outside the database. Here is a simple example that uses sqlplus to be the daemon:
A quick and dirty way to do this is with a csh script and sqlplus as such (cut and pasted from another email)
Ok, so can you do this without C? Yes. Here is a PL/SQL subroutine you can install in your schema:
create or replace procedure host( cmd in varchar2 )
as
status number;
begin
dbms_pipe.pack_message( cmd );
status := dbms_pipe.send_message( 'HOST_PIPE' );
if ( status <> 0 ) then raise_application_error( -20001, 'Pipe error' );
end if;
end;
/
Here is a C-Shell script you can run in the background, it should be named
host.csh. host.csh will be run by you after the db is up. it will create
temporary scripts "tmp.csh" that it will run. the last thing these tmp.csh
scripts do is re-run host.csh to get the next request....
-------------------- bof ----------------------------
#!/bin/csh -f
sqlplus tkyte/tkyte < tmp.csh
set serveroutput on
declare
status number;
command varchar2(255);
begin
status := dbms_pipe.receive_message( 'HOST_PIPE' );
if ( status <> 0 ) then
dbms_output.put_line( '#exit' );
else
dbms_pipe.unpack_message( command );
dbms_output.put_line( '##!/bin/csh -f' );
dbms_output.put_line( '#' || command );
dbms_output.put_line( '#exec host.csh' );
end if;
end;
/
spool off
"EOF"
chmod +x tmp.csh
exec tmp.csh
----------------------- EOF ---------------------------------
If you run this in the background (The script), you'll be able to have it
execute any host command you want. Run this in one window for example and in
anther window go into sql*plus and try:
SQL> exec host( 'ls -l' );
SQL> exec host( 'uptime' );
SQL> exec host( 'echo Hello World' );
SQL> exec host( 'exit' );
You'll see the output of ls -l, uptime, and echo happen on the other window
where the shell script is running (shows you a way to debug pl/sql routines, use
"host( echo some string )" and you'll get real time feedback from your pl/sql
procedure).....
Make sure you understand the ramifications of the above. It does absolutely no
checking anywhere that only valid commands are executed. If you run this as the
oracle account and someone sends "rm -rf *" -- watch out. This is an example --
it needs to be more robust.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/756652/viewspace-242196/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle檢視執行計劃的命令Oracle
- oracle中多列轉行Oracle
- Docker命令-docker exec-在執行的容器中執行命令Docker
- Go語言中用 os/exec 執行命令的五種姿勢Go
- Oracle ASM使用asmcmd中的cp命令來執行遠端複製OracleASM
- docker 中vim 命令 無法執行Docker
- [ORACLE] SQL執行OracleSQL
- oracle列轉行Oracle
- 命令執行漏洞
- Docker執行命令Docker
- Oracle資料庫關於SQL的執行計劃(轉)Oracle資料庫SQL
- Windows更新+中間人=遠端命令執行Windows
- 從反序列化到命令執行 - Java 中的 POP 執行鏈Java
- [轉載]ubuntu中執行python指令碼UbuntuPython指令碼
- 從Java到JVM到OS執行緒睡眠JavaJVM執行緒
- .net執行cmd命令
- Java執行cmd命令Java
- 收集 Linux 命令列執行的命令Linux命令列
- oracle執行計劃------未走索引,隱式轉換的坑Oracle索引
- 在 Ruby 中執行 Shell 命令的 6 種方法
- 在 Windows 中執行 Linux 命令的 4 種方法WindowsLinux
- 在指令碼中呼叫git命令:指定git命令執行上下文指令碼Git
- anaconda中執行pip命令顯示不是內部或外部命令
- oracle 固定執行計劃Oracle
- oracle執行java程式碼OracleJava
- Oracle sql執行計劃OracleSQL
- Oracle WebLogic 曝 0day 漏洞,攻擊者可遠端執行命令OracleWeb
- [20210804]oracle rac執行命令crs_stat -t -v緩慢的分析.txtOracle
- python裡執行shell命令或cmd命令Python
- 【Mongo】shell命令列模式執行mongo命令Go命令列模式
- 在Oracle中,如何得到真實的執行計劃?Oracle
- 監控 redis 執行命令Redis
- Linux 後臺執行命令Linux
- 跟蹤執行命令T
- linux執行環境&命令Linux
- PHP命令執行集錦PHP
- 關於Python指令碼中執行adb命令的方法Python指令碼
- shell指令碼命令 執行python檔案&python命令列執行python程式碼指令碼Python命令列