简体   繁体   English

通过sqlplus取消Shell脚本

[英]RUnning shell script through sqlplus

I am logged in as oracle in a prod env and I have a requirement to run SHELL scripts on remote hosts while I am in SQLPLUS. 我在产品环境中以oracle身份登录,并且我在使用SQLPLUS时需要在远程主机上运行SHELL脚本。 I am trying to do this via python. 我正在尝试通过python做到这一点。 Is there any way to do it? 有什么办法吗?

I am able to run SQL scripts or sql commands from sqlplus like the following :- 我能够从sqlplus运行SQL脚本或sql命令,如下所示:-

session = Popen(['sqlplus','-S','abc/abc@'+str(hostname)+':1000/'+str(dbname)+''], stdin=PIPE, stdout=PIPE, stderr=PIPE)
    session.stdin.write('SPOOL '+str(op_file)+' \n'
                        ' '+str(data)+ '\n');

    session.stdin.write(' ; \n')
    session.stdin.write('exit \n')
    session.stdin.flush()
    stdout, stderr = session.communicate()

But when I want to run a shell script is there any way of doing it through sqlplus itself, coz the other way of logging in via ssh and sudoing in as oracle is not possible 但是,当我想运行shell脚本时,是否有任何方法可以通过sqlplus本身来完成它,因为通过oracle无法通过ssh和sudoing登录的另一种方法

I think this is one of the ways of doing it using PLSQL:- 我认为这是使用PLSQL做到这一点的方法之一:

http://www.dba-oracle.com/t_execute_shell_script_plsql_procedure.htm http://www.dba-oracle.com/t_execute_shell_script_plsql_procedure.htm

But am not sure. 但是不确定。

SQL*Plus is a client application. SQL * Plus是一个客户端应用程序。 It can spawn processes on the client machine which would run shell scripts on the client. 它可以在客户端计算机上生成将在客户端上运行shell脚本的进程。 It cannot spawn processes on the database server. 它不能在数据库服务器上生成进程。

As you've linked to, you can use the dbms_scheduler package on the database server to spawn processes on the server that would run batch files. 链接到该数据库后,可以在数据库服务器上使用dbms_scheduler软件包在服务器上生成将运行批处理文件的进程。 You can do something similar with a Java stored procedure since that also runs on the server. 您可以对Java存储过程执行类似的操作,因为它也可以在服务器上运行。 dbms_scheduler also has the ability to run jobs on remote servers if the appropriate scheduler agents are installed but this seems unlikely to be particularly helpful in the vast majority of situations. 如果安装了适当的调度程序代理, dbms_scheduler还具有在远程服务器上运行作业的能力,但这在绝大多数情况下似乎不太有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM