Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Location
    Rome, Italy
    Posts
    81

    Question Unanswered: stopping main shell when jobs go wrong

    hi friends,
    I would like to trap the error exit status of the background jobs run from a main shell script. So I have run.myjobs.sh:
    ----------------------------------
    for i in 1 2 3 4 5
    do
    my.job.sh &
    done
    ---------------------------
    how can I test whather any of the jobs finishes with exit status !=0 ? The jobs must be run in background.

    Thank you in advance,
    ducasio

  2. #2
    Join Date
    Aug 2004
    Location
    Rome, Italy
    Posts
    81
    hi guys,
    actually I found a solution:
    ------------------------------------
    ind=0
    for i in 1 2 3 4 5
    do
    ind=`expr $ind + 1`
    my.job.sh &
    RC_ARRAY[$ind]=$!
    done

    for i in ${RC_ARRAY[*]}
    do
    wait $i
    RC=$?
    if test $RC -ne 0
    then
    echo "ERROR: Return Code = $RC"
    exit $RC
    fi
    done
    -------------------------------------

    But I am interested to know if there's any other way to manage the situation with job controls or with trapping the child process.

    thank you again,
    ducasio

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •