简体   繁体   中英

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. I am trying to do this via python. Is there any way to do it?

I am able to run SQL scripts or sql commands from sqlplus like the following :-

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

I think this is one of the ways of doing it using PLSQL:-

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

But am not sure.

SQL*Plus is a client application. It can spawn processes on the client machine which would run shell scripts on the client. 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. You can do something similar with a Java stored procedure since that also runs on the server. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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