Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: shell scripting help
Hello everybody first of all I'm sorry for the long and for my
english. I think all things said related to this subject are not 100%
correct.
I'm trying to clarify how to work with backgroud processes in shell.
A shell like:
p1& p2& p3&
it seems to be ok because of it executes p1 and p2 and p3 in background and it waits to finish three process before execute i1. But for me it has very important bugs:
The command "wait" waits untill all processes haved terminated but it
"always" return 0.
The command "wait pid1 ... pidN" waits until pid1, ..., pidN processes
have terminated and it returns the return status of the pidN process.
Let's do me some examples:
mymachine:/usr/users/myuser> (sleep 40 && exit 1) &
[1] 1060183
mymachine:/usr/users/myuser> sleep 40 &
[2] 1181744
mymachine:/usr/users/myuser> wait
[2] + Done sleep 40 &
[1] + Done(1) (sleep 40 && exit 1) &
mymachine:/usr/users/myuser> echo $?
0
It seems to have a good behaviour.
mymachine:/usr/users/myuser> sleep 40 &
[1] 1462190
mymachine:/usr/users/myuser> (sleep 40 && exit 1) &
[2] 1171882
mymachine:/usr/users/myuser> wait
[2] + Done(1) (sleep 40 && exit 1) &
[1] + Done sleep 40 &
mymachine:/usr/users/myuser> echo $?
0
Ummmm, the last process executed returns 1 but the wait process returns 0
mymachine:/usr/users/myuser> sleep 40 &
[1] 1192834
mymachine:/usr/users/myuser> (sleep 40 && exit 1) &
[2] 1092754
mymachine:/usr/users/myuser> wait 1092754 1192834
mymachine:/usr/users/myuser> echo $?
0
Be careful, in spite of the fact the pid "1192834" has started before the wait returns its return status.
mymachine:/usr/users/myuser> sleep 40 &
[1] 1169544
mymachine:/usr/users/myuser> (sleep 40 && exit 1) &
[2] 1221012
mymachine:/usr/users/myuser> wait 1169544 1221012
mymachine:/usr/users/myuser> echo $?
1
This is the correct behaviour.
In my expertise I recommend the following:
Sql template:
whenever sqlerror exit sql.sqlcode rollback --- or commit whenever oserror exit failure rollback --- or commit
... ... sql code ...
To execute sqlplus use:
sqlplus -L user/pass_at_tns @sqlscript
An example of shell scripts (in korn):
p1 1>$TMPDIR/p1_$$.log 2>&1 & Pid1=$! p2 1>$TMPDIR/p2_$$.log 2>&1 & Pid2=$! p3 1>$TMPDIR/p3_$$.log 2>&1 & Pid3=$!
wait $(eval echo $"Pid${n}")
ret_status=$?
cat p${n}_$$.log
if [ "${ret_status}" != "0" ]; then
echo "ERROR - Process p${n} have terminated with ${ret_status}" TotalErros=$((${TotalErros}+1)) else echo "OK - Process p${n} have terminated with ${ret_status}"fi
### ERRROR
else
### OK
fi
Be carefuly if you use csh because of it has the wait function built in and is possible different behaviour.
HTH Enrique
On 8/4/05, oracle-l-bounce_at_freelists.org <oracle-l-bounce_at_freelists.org> wrote:
> Hi Listers, > > I have a korn shell script which needs to run 3 sqlplus > scripts in parallel then run the final sqlplus script. Is there a way > to ensure that sqlplus scripts 1 thru 3 completes before running the > final sqlplus script? I am a newbie in shell scripting. > > use wait (a shell builtin): > > foo1 & > foo2 & > wait > foo3 > --
-- ------------------------------------------------ Enrique -- http://www.freelists.org/webpage/oracle-lReceived on Fri Aug 05 2005 - 03:05:24 CDT
![]() |
![]() |