Shell script process remains after "exit 1"

I have a script that performs an oracle export:

<snip>
if [ ${exp_type} = FULL ]
then
        exp / full=y file=${exp_file} log=${exp_log} direct=y feedback=1000000 STATISTICS=NONE buffer=20000000
else
        exp / full=n owner=${schema_name} file=${exp_file} log=${exp_log} direct=y feedback=1000000 STATISTICS=NONE buffer=20000000
fi

if [ $? -ne 0 ]
then
        echo "Export command failed"
        exit 1
fi
echo "Export command succeeded"
exit 0

If the export succeeds then I get the message and the script ends with no process in memory. However, if it fails, the script stops (ie. doesn't display "Export Succeeded") but the process remains:

> ps -ef|grep export
oracle   23241     1  0 10:04 pts/1    00:00:00 /bin/bash /u01/ct_scr/export.sh TAXTST FULL Y

Anyone know what's happening here?

try

ps -ef |grep PID

to see if the process script has any kids, these maybe holding it open, while it waits for them to finish.
Oh, PID above is the result of the original ps -ef that you did.

No, nothing:

> ps -ef|grep 23241
oracle   23241     1  0 10:04 pts/1    00:00:00 /bin/bash /u01/ct_scr/export.sh TAXTST FULL Y
oracle   24421  9040  0 10:22 pts/1    00:00:00 grep 23241

ok, a little more diagnosis:

The Y flag on the script is to indicate whether the dump should be compressed via pipe. executing the script with: "/u01/ct_scr/export.sh TAXTST FULL N" exits just fine.

Here's the code for $3=Y:

if [ ${compress} = Y ]
then

        pipe_name=${exp_loc}/compress_${ORACLE_SID}_${schema_name:-FULL}_${today}_p

        # remove any existing pipe
        rm -f ${pipe_name}

        # Make a new pipe
        /bin/mknod ${pipe_name} p

        # initiate compression process on the new pipe to run in the background
        gzip -c < ${pipe_name} > ${exp_file}.gz &

        # Re-direct export output to the pipe
        exp_file=${pipe_name}

fi

I also included a cleanup function which is called before the exit 1:

cleanup()
{
if [ ${compress:-N} = Y ]
then
        rm -f ${pipe_name}
fi
}

The pipe and background gzip command are gone once the script ends but maybe the script doesn't know that and hangs around?

Let me know if I've confused the heck out of you. I'd post the whole script but it's kinda long...

Confirmed. feeding the pipe some dummy text (with an implicit EOF) before removing it causes the script to exit correctly:

cleanup()
{
if [ ${compress:-N} = Y ]
then
        echo "fail" >> ${pipe_name}
        rm -f ${pipe_name}
fi
}

Presumably the issue is coming from the gzip command not returning an exit code to the script process before it disappears, keeping the script process open. Killing the pipe before it feeds the gzip process anything seems to leave the script process in limbo. Feeding the dummy text is an OK workaround but it leaves me with the .gz file after a failure.

Does anyone know how to send JUST the EOF to a pipe? I'm hoping that this will cause the background gzip process to exit cleanly without creating a .gz file.