Did my script execute successfully ?

Hi,

I have two scripts viz

and

I am running them in background.
I wish to know if both the scripts completed execution successfully.

So this is what I have done

/tmp/commet/bin/connectdb1.sh &
condb1=$?
/tmp/commet/bin/connectdb2.sh &
condb2=$?

However, I am getting error when trying to check.

if [$condb1 -ne 0] || [$condb2 -ne 0] ; then
echo " Error executing either of the two scripts ...."

[0: command not found

Is this the correct approach ? Why the error ?

You should use code tags in your post. It makes it easy to read.
With more than 200 post I guess you should now the rules here.

You didn't tell us your shell. I will assume ksh.

So how do you know your scripts have finished? You are simply getting the return code from the submission of a background job. I think you need something more like:-

(/tmp/commet/bin/connectdb1.sh;print $?>/tmp/db1.ret )&
(/tmp/commet/bin/connectdb2.sh;print $?>/tmp/db2.ret )&

wait

condb1=`cat /tmp/db1.ret`
condb2=`cat /tmp/db2.ret`

if [ $condb1 -ne 0 ] || [ $condb2 -ne 0 ]
then
   echo " Error executing one of the two scripts ...."
fi

Note the extra spaces in the if statement between the square brackets and the values. This might not apply in your shell, but it's a good bet it does looking at your message. Pretty basic stuff, but easy to get wrong.

This is a bit of a clunky way to do it, but this way will wait for both to complete before you get an answer. Is that okay? Be careful that there are no other background tasks, or it will wait for them too.

If you need to know as soon as one finished, there are ways to look at that, but hopefully the simple way will work for you.

Another way might be a co-process, but I'm not so good with them.

I hope that this helps,
Robin
Liverpool/Blackburn
UK

It's BASH Shell. So, if you can help me code the above in BASH style. Can you explain the wait logic as I am not sure how long will it take to complete execution.

You might want to put the success or failure checks into your connectdb1.sh and connectdb2.sh scripts, referencing the specific script names in the output from each.

That way you'll get more specific info on each script's status.

because I use shell i am getting this error

[: -ne: unary operator expected

Can someone give me the BASH equivalent of the below ?

(/tmp/commet/bin/connectdb1.sh;print $?>/tmp/db1.ret )& (/tmp/commet/bin/connectdb2.sh;print $?>/tmp/db2.ret )& wait condb1=`cat /tmp/db1.ret` condb2=`cat /tmp/db2.ret` if [ $condb1 -ne 0 ] || [ $condb2 -ne 0 ] then echo " Error executing one of the two scripts ...." fi

Please use Code Tags
And do not quote complete post above you.

Have a read of the manual page for bash There should be a section on Shell Grammar to give you the structures and format you need. It looks pretty much the same as I have given you for ksh.

It's better to explore and learn than have it handed to you. It makes next time easier.

Maybe if you display the values before dong the if statement, it will help you debug it. It might be that the value is being read in as text rather than a numeric, so maybe you need to introduce something like:-

typeset -i condb1 condb2

...to force them to be integers.

Robin