Compressing output via pipes

O

Orr, Steve

Oracle provides an export utility (exp) and I have a shell script which
compresses its output (not stdout) thru a pipe but l need a platform
portable Python script for this.

Here's the shell script:
------------------------------------------------------------------
#!/bin/bsh
LOG_NAME='/tmp/expzip.log'
FILENAME='/tmp/expzip.dmp'
/bin/mknod $FILENAME p
/usr/bin/gzip <$FILENAME>$FILENAME.Z &
$ORACLE_HOME/bin/exp system/manager@local FULL=Y file=$FILENAME
log=$LOG_NAME
/bin/rm $FILENAME
------------------------------------------------------------------


Here's a Python script which runs the exp utility without on the fly
compression:
------------------------------------------------------------------
import os
expcmd = '/u01/app/oracle/product/9.2/bin/exp'

def expDB(theUser,thePW,theSrvr,dmpFile,logFile):
cmd='%s userid=%s/%s@%s full=y file=%s
log=%s'%(expcmd,theUser,thePW,

theSrvr,dmpFile,logFile)
cmdout = os.popen(cmd)
cmdout.close()

def main():

expDB('system','manager','local','/tmp/exptest.dmp','/tmp/exptest.log')

if __name__=='__main__':main()
------------------------------------------------------------------


I want to compress the *.dmp dump file on the fly without having to
compress an intervening file. I know I need to do something with pipes
and/or os.dup2() but I'm struggling. Has anyone done something like
this?


TIA,
D. B. Dweeb
 
P

Paul Moore

Orr said:
Oracle provides an export utility (exp) and I have a shell script which
compresses its output (not stdout) thru a pipe but l need a platform
portable Python script for this.

How platform portable? If you want to do this on Windows, you're
basically out of luck, as Windows doesn't support named pipes like
this.

If you're talking just Unix variants, I'd guess that a minimal shell
script is as portable as you need.

Paul
 
J

Jeremy Bowers

I want to compress the *.dmp dump file on the fly without having to
compress an intervening file. I know I need to do something with pipes
and/or os.dup2() but I'm struggling. Has anyone done something like this?

Are you sure you need pipes?

http://www.python.org/doc/current/lib/module-zlib.html
http://www.python.org/doc/current/lib/module-gzip.html

You probably should use os.popen2 to read the output directly and stuff it
into a GzipFile instead of letting the operating system write the file,
but I'm not 100% certain I understand what you're looking for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top