I have some code to calculate the size of an oracle export dump. I can run the command from the command line; however, in the jython script it hangs and does not return control to the screen. I have to perform a ctrl-C and clean up the processes. I have tried os.system(cmd) to run this code, popen2.popen3, and os.poen. My goal is to write the number of block to a file. Thanks in advance
here's a sample of my code.
here's a sample of my code.
Code:
#!/usr/bin/env /opt/datapalette/jython/jython
# (c) StrataVia Corp.
import os, sys, tempfile
#Header = """${Header}""".strip()
#oraHome = '${Header.oraHome}'
oraHome = '/u01/app/oracle/product/10.1.0/robodb_1'
#sourceSid = '${Header.sourceSid}'
sourceSid = 'exbeta'
#schemaOwner = '${Header.schemaOwner}'
schemaOwner = 'scott'
login = "\"'/ as sysdba'\""
osUser = 'oracle'
#def printHeader(oraHome, oraTab):
# print '${Header.Start}'
# print Header
# print 'OraHome="'+oraHome+'"'
# print 'OraTab="'+oraTab+'"'
# print '${Header.Stop}'
def SetOracleEnvironment():
path = os.environ['PATH']
os.environ['ORACLE_SID']=sourceSid
os.environ['ORACLE_HOME']=oraHome
os.environ['SHLIB_PATH']=oraHome + '/lib'
os.environ['LD_LIBRARY_PATH']=oraHome + '/lib'
os.environ['PATH']=path + ':' + oraHome + '/bin'
def calcExpsize():
fd = tempfile.mktemp('sizeresults.lst')
if os.path.exists('/tmp/exp_pipe'):
print '<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>'
print 'Pipe exists proceeding with size calculations'
SetOracleEnvironment()
cmd = 'sudo -u ' + osUser + ' exp ' + login + ' owner=' + schemaOwner + ' file=/tmp/exp_pipe statistics=none |dd if=/tmp/exp of=/dev/null bs=1024 > ' +
fd + ' 2>&1'
print cmd
child = os.popen(cmd)
out = child.read()
# for line in out
err = child.close()
print out
print "Size calculation complete."
sys.exit(0)
elif not os.path.exists('/tmp/exp_pipe'):
print 'Creating pipe'
SetOracleEnvironment()
cmd = 'sudo -u ' + osUser + ' mknod /tmp/exp_pipe p\n'
rc = os.system(cmd)
if (rc == 0):
cmd = 'exp ' + login + ' owner=' + schemaOwner + ' file=/tmp/exp_pipe statistics=none |dd if=/tmp/exp of=/dev/null bs=1024\n'
out = os.popen(cmd).read()
print out
else:
print "Error while calculating export size"
size=calcExpsize()
sys.exit(0)