Results 1 to 4 of 4

Thread: while loop

  1. #1
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25

    Unanswered: while loop

    Ok, I have a function that I need help with:

    In a text file (PL_SENDEVENT), I have the following line:
    CHANGE_STATUS INACTIVE

    and another file (PL_JOBS) with the following lines:
    TEST
    TEST1

    ------------------------------------------------------------

    What I'm trying to do is change the STATUS of TEST and TEST1 to the status that I specify in the file which is INACTIVE (or IN) in this case. I do not want the script to exit until both jobs have been verified that they are in an INACTIVE (IN) status. Not going well so far. As it stands, it exits successfully once it sets TEST to INACTIVE and doesn't even check TEST1. If the jobs are not in an INACTIVE status, I want it to check again until they both are. Any help would be greatly appreciated.

    Thanks,
    Jeff

    --------------- code --------------------------------------

    cat $PL_DIR/PL_SENDEVENT | while read event status
    do
    case $event in
    CHANGE_STATUS)
    cat $PL_DIR/PL_JOBNAME | while read job
    do
    sendevent -E CHANGE_STATUS -s ${status} -J ${job}
    done
    case $status in
    INACTIVE) export ST=IN ;;
    ON_HOLD) export ST=OH ;;
    ON_ICE) export ST=OI ;;
    TERMINATED) export ST=TE ;;
    *) echo "Invalid Status!"; exit 1 ;;
    esac
    rc3=1
    while (($rc3 > 0))
    do
    sleep 5
    cat $PL_DIR/PL_JOBNAME | while read job
    do
    $AUTOSYS/bin/autorep -J ${job} -l0 | sed '1,4d' |
    if [ `awk '{print $6}'` == ${ST} ]; then
    echo "Status is set for ${job}!"
    rc3=0
    fi
    done
    done ;;

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Try replacing the last part with this:
    Code:
    rc3=1
    while (($rc3 > 0))
    do
      sleep 5
      rc7=0
      cat $PL_DIR/PL_JOBNAME | while read job
      do
        $AUTOSYS/bin/autorep -J ${job} -l0 | sed '1,4d' | \
        if [ `awk '{print $6}'` == ${ST} ]; then
          echo "Status is set for ${job}!"
          (( rc7 += 1 ))
        fi
      done
      [ $rc7 == `wc -l $PL_DIR/PL_JOBNAME` ] && rc3=0      
    done 
    ;;

    Or something around those lines...
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25
    That worked! Thank you very much!

    Jeff

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    You're welcome!
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

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