If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > while loop

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-10-04, 14:22
normanjr29 normanjr29 is offline
Registered User
 
Join Date: Apr 2004
Location: Winston-Salem, NC
Posts: 25
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 ;;
Reply With Quote
  #2 (permalink)  
Old 12-10-04, 16:31
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
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
Reply With Quote
  #3 (permalink)  
Old 12-13-04, 15:02
normanjr29 normanjr29 is offline
Registered User
 
Join Date: Apr 2004
Location: Winston-Salem, NC
Posts: 25
That worked! Thank you very much!

Jeff
Reply With Quote
  #4 (permalink)  
Old 12-13-04, 17:31
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On