If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Shell script not exiting Gracefully

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-13-07, 11:40
dbadam dbadam is offline
Registered User
 
Join Date: Sep 2004
Posts: 12
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
Reply With Quote
  #2 (permalink)  
Old 02-13-07, 18:14
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
  #3 (permalink)  
Old 02-14-07, 14:21
dbadam dbadam is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 02-15-07, 05:18
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
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
Reply With Quote
  #5 (permalink)  
Old 02-15-07, 08:35
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
  #6 (permalink)  
Old 02-16-07, 10:04
dbadam dbadam is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 02-19-07, 02:27
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
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 07:46.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On