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
exiting from script arghya_owen Shell Programming and Scripting 1 06-02-2008 06:36 AM
Exiting from script when error occurs Sreejith_VK Shell Programming and Scripting 4 04-25-2008 03:53 AM
Script Not Exiting??? lesstjm Shell Programming and Scripting 1 07-11-2007 11:58 AM
PHP5 Script 'Freeze' before exiting Unbeliever Shell Programming and Scripting 4 05-10-2007 11:32 AM
exiting in c ruffenator High Level Programming 3 04-28-2002 02:31 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 02-07-2007
smithK smithK is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 3
Shell script not exiting Gracefully

Hi
we are seeing strange behaviour , when we execute shell script it is successfully executing but it's PID is still hanging when we see ps -ef | grep script1.ksh until we do Kill <PID>


$script1.ksh
$
$ ps -ef | grep script1.ksh
user1 249996 1 0 10:48:40 pts/1 0:00 /usr/bin/ksh script1.ksh

Inside script we are using
exit command before completion of script



OS : AIX 5.3.0.0

Can someone advise

Let me know if you need any additional information .


thanks
SmithK
  #2 (permalink)  
Old 02-07-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Hard to tell if you don't provide the code of the script.
  #3 (permalink)  
Old 02-07-2007
smithK smithK is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 3
I have narrowed down the issue we are using gzip in the script ..to compress the file ..we write to the pipe then we will compreess using gzip
below is the sample code

#!/usr/bin/ksh

/usr/sbin/mknod NAMEDPIPE p

gzip -1 < NAMEDPIPE > EXPORT &
db2 "export to NAMEDPIPE of del select * from test" ##db2 command to
## export data
rm -f NAMEDPIPE


After completion of the script , successfully , i still see the script PID , i don't see connection any connection to DB , Basically script is hanging in there doing nothing , I suspect gzip -1 < NAMEDPIPE > EXPORT & not termenating ....properly

Thanks
Smithk
  #4 (permalink)  
Old 02-07-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by smithK
I have narrowed down the issue we are using gzip in the script ..to compress the file ..we write to the pipe then we will compreess using gzip
below is the sample code

#!/usr/bin/ksh

/usr/sbin/mknod NAMEDPIPE p

gzip -1 < NAMEDPIPE > EXPORT &
db2 "export to NAMEDPIPE of del select * from test" ##db2 command to
## export data
rm -f NAMEDPIPE


After completion of the script , successfully , i still see the script PID , i don't see connection any connection to DB , Basically script is hanging in there doing nothing , I suspect gzip -1 < NAMEDPIPE > EXPORT & not termenating ....properly

Thanks
Smithk
In your script you create a background process which reads from the named pipe (gzip).

Next you start a process (db) which writes to the named pipe.

As soon as the writing process (db) is done you remove the named pipe.

Most likely by that time the reading process (gzip) did not yet complete reading all data from the named pipe.

Since the named pipe (and the data in it) has been removed the reading process will never receive an EOF.

Basically the reading process is left with an open file descriptor which refers to something that doesn't exist any more.

Therefore the gzip command will not terminate.

Since this process is a child process of your script, your script will not terminate.

It only seems as if it terminated, all it did was returning controll back to your shell. Underneath it's waitingfor a dead of child.

After executing your script, I expect you will not only be able to find your script with ps in the process table, but the gzip as well.

Furthermore, I do understand why you use a NAMED pipe for something like this.

Wouldn't it be much easier to use:

db2 "export to EXPORT of del select * from test"
gzip -1 EXPORT

I'm not familiar with the db command, but I assume
db2 " select * from test"
would produce the output to your screen.

If so, why not use an "anonymous" pipe:
db2 "select * from test" | gzip -1 - > EXPORT.gz

It might work with a NAMED pipe as well if you switch the 2 commands:
:
#!/usr/bin/ksh

/usr/sbin/mknod NAMEDPIPE p

db2 "export to NAMEDPIPE of del select * from test" & ##db2 command to
## export data
gzip -1 < NAMEDPIPE > EXPORT.gz

rm -f NAMEDPIPE
  #5 (permalink)  
Old 02-08-2007
smithK smithK is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 3
I think yes
gzip -1 < NAMEDPIPE_FILE > EXPORT_FILE &

causing the issue , we are writting to the pipe since we don't have enough space on filesystem to export data , we write data into Pipe and then compress in the background .

we can't do like this
db2 "export to NAMEDPIPE of del select * from test" &
gzip -1 < NAMEDPIPE > EXPORT.gz

Since if we hvae any error on export like table not found ... next step gzip is waitting for the PIPEFILE , and script itself is hanging without proceeding to next step.


Any insight ?

thanks
smithk
  #6 (permalink)  
Old 02-08-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
You could try to build a delay before removing the pipe.

sleep 30
rm -f NAMEDPIPE
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 09:37 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