The UNIX and Linux Forums  

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
wait ${!} risshanth Shell Programming and Scripting 2 06-06-2008 04:57 AM
About wait Puntino UNIX for Dummies Questions & Answers 5 04-27-2008 05:07 AM
Need to execute 2 scripts, wait, execute 2 more wait, till end of file halo98 Shell Programming and Scripting 1 08-01-2006 05:42 PM
86% CPU for wait big123456 UNIX for Advanced & Expert Users 3 11-04-2005 10:07 AM
Help with wait command ultraman Shell Programming and Scripting 1 10-21-2002 12:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-28-2005
lesstjm lesstjm is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 59
Wait Command

Does anyone have an example of a korn shell scripts kicking of multiple background processes and then using the wait command to get the return code from those processes?

I want to write a program that kicks off multiple Oracle procedures and then wait for the return code before I procede. Thanks.
  #2 (permalink)  
Old 03-28-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by lesstjm
Does anyone have an example of a korn shell scripts kicking of multiple background processes and then using the wait command to get the return code from those processes?

I want to write a program that kicks off multiple Oracle procedures and then wait for the return code before I procede. Thanks.
Here is a section of a script that I am presently working on that loads several sqlldr threads that will each load a section of one data file (no, I can't use direct path ). I save each thread's PID and wait for all of them to finish. I use a sqlplus co-process to obtain load parameters so using "wait" without specifying PIDs wants to wait of the co-process to complete as well, which I cannot do. If I specify all of my PIDs to "wait", it would no wait for all of them to complete. I settled on a loop of my own that tests to see if the PIDs have finished running.

I save my return codes in a log file and parse it and the logs once everything is done to determine just what happed during the parallel load operation.


Code:
            # For each of the desired threads
            while [ ${SQLLDR_THREAD_COUNTER} -le ${SQLLDR_THREADS} ]
            do
...
                # Start a sqlldr thread and make it a background task
                {
                    # Run sqlldr task
                    print ${OLS_KEY} |
                              sqlldr ${OLS_USER}@${OLS_SID} \
                                     control=${CTL_FILE} \
                                     data=${UPLOAD_FILE} \
                                     errors=${SQLLDR_ERRORS} \
                                     rows=${SQLLDR_ROWS_IN_BIND_ARRAY} \
                                     bindsize=${SQLLDR_BINDSIZE} \
                                     direct=${SQLLDR_LOAD_USING_DIRECT_PATH} \
                                     silent=header,feedback \
                                     log=${LOG_FILE}_${SQLLDR_SKIP}.log \
                                     bad=${BAD_FILE}_${SQLLDR_SKIP}.bad \
                                     discard=${DSCRD_FILE}_${SQLLDR_SKIP}.dis \
                                     skip=${SQLLDR_SKIP} \
                                     load=${SQLLDR_ROWS_TO_LOAD} > /dev/null 2>&1

                    # Save exit status code in a temp file with all others
                    rc=$?
                    print "${SQLLDR_THREAD_COUNTER}:${rc}" >> ${SQLLDR_PARALLEL_RESULTS_FILE}

...
                } &

                # Save the background process ID
                PID_LIST="$PID_LIST $!,"
                # Compute next thread number
                ((SQLLDR_THREAD_COUNTER += 1 ))
            done

            #wait $PID_LIST
            # Simulate wait command since wait doesn't appear to wait for all
            # PIDs in $PID_LIST
            typeset THREAD_CNT=$(ps -p $(print ${PID_LIST} | tr -d ' ' | nawk '{print substr($0,1,length($0)-1)}') | wc -l)
            while [ $(( THREAD_CNT - 1 )) -gt 0 ]
            do
                update_process_status \
                     ${RUN_ID:-0} \
                     ${P_FN_CD} \
                     "InProgress" \
                     "staging ${FILE_TYPE} - sqlldr - threads still running: $(( THREAD_CNT - 1))" \
                     0
                sleep 2
                THREAD_CNT=$(ps -p $(print ${PID_LIST} | tr -d ' ' | nawk '{print substr($0,1,length($0)-1)}') | wc -l)
            done

I hope this helps; it works great for my needs.

Thomas
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:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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