The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Startup Script "run process with Timer" zawmn83 Shell Programming and Scripting 0 08-21-2008 09:57 AM
How to include RETURN KEY with Background process "&" in Shell Script racbern Shell Programming and Scripting 1 03-11-2008 07:30 AM
Q: Recording shell script screen output using "script" command ? lalfonso.gomez Shell Programming and Scripting 4 01-18-2007 09:31 PM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 04:15 AM
My "Bread and Butter" Process Keep Alive Perl Script.... Neo Tips and Tutorials 0 01-08-2005 05:17 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-21-2008
Squeakygoose Squeakygoose is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 14
Shell script process remains after "exit 1"

I have a script that performs an oracle export:

Code:
<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:

Code:
> 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?
  #2 (permalink)  
Old 10-21-2008
wempy's Avatar
wempy wempy is offline
Registered User
  
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 205
try
Code:
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.
  #3 (permalink)  
Old 10-21-2008
Squeakygoose Squeakygoose is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 14
No, nothing:

Code:
> 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
  #4 (permalink)  
Old 10-21-2008
Squeakygoose Squeakygoose is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 14
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:
Code:
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:

Code:
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...
  #5 (permalink)  
Old 10-21-2008
Squeakygoose Squeakygoose is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 14
Confirmed. feeding the pipe some dummy text (with an implicit EOF) before removing it causes the script to exit correctly:

Code:
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0