help on script execution

Hi,

Please help me on the below code of line of what it actually does

${Script_dir}/scrip1.sh &
export script1_pid=$!

${Scipt_dir}/script2.sh &
export script2_pid=$!

${Scrip_dIR}/script3.sh &
export script3_pid=$!

wait ${script1_pid} //could u tell me wht this statement isexport script1_rc=$?

wait ${script2_pid} // all these wait statements execute sequentially or parllel
export script2_rc=$?

wait ${script3_pid}
export script3_rc=$?

if [ ${script1_rc} -ne 0 ]; then
echo script 1 load has errors.
exit 1

elif [ ${script2_rc} -ne 0 ]; then
echo script2 load for has errors.
exit 1

elif [ ${script3_rc} -ne 0 ]; then
echo script3 load has errors. $
exit 1
fi

Here if the first script1 fails then the rest of wait commnads will not be executed. Is there any way to let all the other things also execute if script 1 fails. I mean to say that is there any way that wait statements execute parllely ie wait for that particular pids parllely.

This is complicated. If you just have

wait

the shell will stop processing until ALL background processes have completed. However, then, you will not be able to capture the exit value of each process as it terminates.

What I don't understand is why "the rest of wait commnads will not be executed" if script1 fails. Rather, wait should return immediately for a failed command or non-existent process. Are you using ksh or bash?

Thank you otheus.

I am using AIX unix.

Could u please tell me the sequence the process follows if any scripts fail.

for example:

if script1 fails then will the process wait to script2 and script3 to fail/execute successfully, before processing the statements that it sholud execute in case script1 fails.

Please throw some knowledge on this.

Yes. All processes must complete (failure or success) before any error message is shown.

Thank you otheus.

Is there anyway for this script to work in such a way that

if script 2 completes or fails before script 1 completes or fails, then all the statements for script 2 complete/fail should execute without waiting for script1 to complete/fail.

I think you have a typo. Please check your post and re-edit.

hi otheus

Is there anyway for this script to work in such a way that
if script 2 completes/fails before script 1 (completes/fails) then all the statements for script 2 (if it completes/fails) should execute without waiting for script1 to complete/fail

What you are asking still does not make sense to me. If script2 completes or fails before script1, then script2 has already completed and does not need to execute.

Try :

{ script1 || echo "Script 1 failed"; } &
{ script2 || echo "Script 2 failed"; } &
{ script3 || echo "Script 3 failed"; } &
wait