Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2004
    Posts
    12

    Unanswered: Shell script not exiting Gracefully

    Hi

    OS : AIX 5.3
    DB : UDB v8.2

    We use gzip to compree the file since we don't have enough space to store non-compressed file . Below is th way we use gzip

    #!/usr/bin/ksh
    /usr/sbin/mknod ${NAMEDPIPE} p
    gzip -1 < NAMEDPIPE > EXPORT_FILE &
    db2 "export to NAMEDPIPE of del select * from Test"
    rm -f NAMEDPIPE
    exit

    The Problem with this after successful completion , script is not exiting ...if we see ps -ef it schell script still out there without doing anything , I suspect something to do with gzip when we invoke as back ground process,

    I have tried diffrent approach

    db2 "export to NAMEDPIPE of del select * from Test" &
    gzip -1 < NAMEDPIPE > EXPORT_FILE

    This approach seems to be working , But the major disadvantage with this is , if above db2 "export.... fails with some error message , script is hanging at gzip ....looks like it is waitting for some data to compress .

    We cant export the file and then gzip as seperate process .


    Any work arounds for above problem .

    Thank you
    dbadm

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Exporting and gzipping through pipes works fine for me (on Linux) using the steps you provided.

    However, are you sure that your script is correct? At one place you are referring to ${NAMEDPIPE}, and everywhere else just to NAMEDPIPE (no variable). Have you verified the existence and size of the pipe and the gzipped file at the various stages?
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Sep 2004
    Posts
    12
    The ${NAMEDPIPE} was a typo

    It is working for me , but problem is it is not closing gracefully

    example :

    #!/usr/bin/ksh
    /usr/sbin/mknod NAMEDPIPE p
    gzip -1 < NAMEDPIPE > EXPORT_FILE &
    db2 "export to NAMEDPIPE of del select * from Test"
    rm -f NAMEDPIPE
    exit

    If for some reason export failed or gives you a warning , script completes writing error into log file and not cleaning its PID

    I suspect parent script thinks its child gzip still running .....

    i can see script trough ps -ef but not gzip
    Any work around or any better approach


    Thanks
    dbadm

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Will and extra line hurt you in the output file?
    Maybe add
    echo >>NAMEDPIPE
    after the db2 command to ensure gzip will have something to do
    Else check in the script if error occurred then
    kill %% # Kill the gzip job

  5. #5
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    The script works quite fine for me (now in AIX 5.2) - with and without warnings being produced by the EXPORT statements.

    So we are back to knowing the following:
    (a) How about answering the question I posted before, i.e. what's the status if the files/pipes/processes before/after the export?
    (b) What is the exit status of each program started in the script?
    (b) What exactly is the output produced by DB2?
    (c) What is this "log file" you mentioned?
    (d) What do you mean with "not cleaning up its PID"? Is the script still running?
    Please provide more information. Otherwise, we can only guess what might be going on on your system.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  6. #6
    Join Date
    Sep 2004
    Posts
    12
    Thank you pdreyer

    It worked if i use ....echo >>NAMEDPIPE

    I am planning to use below logic

    mkfifo NAMEDPIPE_FILE
    gzip -1 < NAMEDPIPE_FILE > EXPORT_FILE &
    db2 "export to NAMEDPIPE_FILE of del select * from DW.PYMT"
    rc=$?
    if (( $rc != 0 ))
    then
    echo >>NAMEDPIPE_FILE
    fi
    rm -f NAMEDPIPE_FILE
    exit

    But there are chances of export generating some warnings which will genrate rc as non zero number & this operation may corrupt the exported file ....we are planning to use this logic not only for exports but for diffrent operations like Backup ....

    Any work around , without writting anything extra writting into the file ( echo >>NAMEDPIPE_FILE)

    thank you
    dbadam

  7. #7
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    if [ $rc -ne 0 ]
    then
    >NAMEDPIPE_FILE # Truncate file or >>NAMEDPIPE_FILE
    echo "Export failed"
    fi
    rm -f NAMEDPIPE_FILE
    exit $rc
    Last edited by pdreyer; 02-19-07 at 08:46.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •