?
Solved

AIX - Proper format for a While...Read...Do Loop

Posted on 2005-03-29
3
Medium Priority
?
1,823 Views
Last Modified: 2008-01-09
I am NEW to unix programming - and having to do alot of it - so I am pirating code for the most part.  I am stuck right now because I have a text file with records that I am reading to set variables - After I read these and initialize the variables, I am executing a function based on these variables.  The issue I am having is that it keeps running record 1 of my file over and over and does move on to the next record of the file (two currently).  The funky stuff you may not recognize in the function is MaxL code to run an Essbase Replication...

Any help is GREATLY appreciated!

This is a ksh script - the file looks as such:

M3EMGP1 M3EMGP1 M3EMGP2 M3EMGP2 Actual Jan_PY1 Feb_PY1 Mar_PY1
M3EMGP3 M3EMGP3 M3EMGP2 M3EMGP2 Actual Jan_PY1 Feb_PY1 Mar_PY1 Apr_PY1 May_PY1 Jun_PY1

And the applicable code looks as such:
-----------------------------------------------------------------------------------------------------
while read TGAPP TGDB SRCAPP SRCDB CAT M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 junk<

/db2olap/scripts/angietest/CreateReplicationCycle1.txt
do

#not sure this is needed twice - added it to try and solve my issue
read TGAPP TGDB SRCAPP SRCDB CAT M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 < /db2olap/scripts/angietest/CreateReplicationCycle1.txt

## Map the Parms

TGAPP=$TGAPP
TGDB=$TGDB
SRCAPP=$SRCAPP
SRCDB=$SRCDB
CAT=$CAT
M1=$M1
M2=$M2  
M3=$M3  
M4=$M4
M5=$M5
M6=$M6
M7=$M7
M8=$M8
M9=$M9
M10=$M10
M11=$M11
PERIODS=$PERIODS

## echo to the logfile to verify they were set correctly

echo "Variables and Parm Settings"  >> "$LOGFILE" 2>&1

echo "TGAPP =" $TGAPP >> "$LOGFILE" 2>&1
echo "TGDB =" $TGDB >> "$LOGFILE" 2>&1
echo "SRCAPP =" $SRCAPP >> "$LOGFILE" 2>&1
echo "SRCDB = " $SRCDB >> "$LOGFILE" 2>&1
echo "CAT =" $CAT >> "$LOGFILE" 2>&1
echo "M1 = " $M1  >> "$LOGFILE" 2>&1
echo "M2 = " $M2  >> "$LOGFILE" 2>&1
echo "M3 = " $M3  >> "$LOGFILE" 2>&1
echo "M4 = " $M4 >> "$LOGFILE" 2>&1
echo "M5 = " $M5 >> "$LOGFILE" 2>&1
echo "M6 = " $M6 >> "$LOGFILE" 2>&1
echo "M7 = " $M7 >> "$LOGFILE" 2>&1
echo "M8 = " $M8 >> "$LOGFILE" 2>&1
echo "M9 = " $M9 >> "$LOGFILE" 2>&1
echo "M10 = " $M10 >> "$LOGFILE" 2>&1
echo "M11 = " $M11 >> "$LOGFILE" 2>&1


##Create Month variable string
if [ "$M11" != '' ]; then
      PERIODS="$M11,$M10,$M9,$M8,$M7,$M6,$M5,$M4,$M3,$M2,$M1"
elif [ "$M10" != '' ]; then
      PERIODS="$M10,$M9,$M8,$M7,$M6,$M5,$M4,$M3,$M2,$M1"
elif [ "$M9" != '' ]; then
      PERIODS="$M9,$M8,$M7,$M6,$M5,$M4,$M3,$M2,$M1"
elif [ "$M8" != '' ]; then
      PERIODS="$M8,$M7,$M6,$M5,$M4,$M3,$M2,$M1"
elif [ "$M7" != '' ]; then
      PERIODS="$M7,$M6,$M5,$M4,$M3,$M2,$M1"
elif [ "$M6" != '' ]; then
      PERIODS="$M6,$M5,$M4,$M3,$M2,$M1"
elif [ "$M5" != '' ]; then
      PERIODS="$M5,$M4,$M3,$M2,$M1"
elif [ "$M4" != '' ]; then
      PERIODS="$M4,$M3,$M2,$M1"
elif [ "$M3" != '' ]; then
      PERIODS="$M3,$M2,$M1"
elif [ "$M2" != '' ]; then
      PERIODS="$M2,$M1"
elif [ "$M1" != '' ]; then
      PERIODS="$M1"
fi

echo "PERIODS = " $PERIODS >> "$LOGFILE" 2>&1

##Create Replication

function runrepcycle1cmd
{
      /db2olap/bin/essmsh << END
      login $USER $PASSWORD on $SERVER;
      spool stdout on to '/db2olap/scripts/angietest/logs/repcycle1_stdout.txt';
      spool stderr on to '/db2olap/scripts/angietest/logs/repcycle1_stderr.txt';
      create replicated partition $SRCAPP.$SRCDB area '$PERIODS, $CAT, @Levmbrs(ACT,0), @Levmbrs(AAT,0),

@Levmbrs(ServTU,0), @Levmbrs(SubTU,0), @Levmbrs("Expense Product",0), @LevMbrs(Account,0), @Levmbrs(Center,0),

@Levmbrs(Activity,0)' to $TGAPP.$TGDB at $SERVER as $USER identified by '$PASSWORD' using $USER identified by '$PASSWORD' for

creation area '$PERIODS, $CAT, @Levmbrs(ACT,0), @Levmbrs(AAT,0), @Levmbrs(ServTU,0), @Levmbrs(SubTU,0), @Levmbrs("Expense

Product",0), @LevMbrs(Account,0), @Levmbrs(Center,0), @Levmbrs(Activity,0)' update allow;
      spool off;
      exit;
END
}

echo "run the repcycle1cmd function" >> "$LOGFILE" 2>&1

runrepcycle1cmd;

echo "refresh replicated partition $SRCAPP.$SRCDB to $TGAPP.$TGDB at $SERVER all data;"|essmsh -l $USER $PASSWORD -i

unset TGAPP TGDB SRCAPP SRCDB CAT M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 PERIODS

done < /db2olap/scripts/angietest/CreateReplicationCycle1.txt
-----------------------------------------------------------------------------------------------
0
Comment
Question by:Angela_Wilcox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
mathbiol earned 1000 total points
ID: 13658676
Angela,

This is going to be a shot in the dark, as I'm not a unix programmer.  I offer it hoping it gets you unstuck, since I see that no one has responded yet.

I generally do a priming read before the while loop:

   read first record

   while (appropriate condition)
      process record that was previously read
      read next record
   endwhile

I noticed that your code does not use this structure, and I wonder if that would help.

mathbiol
0
 

Author Comment

by:Angela_Wilcox
ID: 13710468
I am not sure whether it will or not - but will give it a try and post the results... Thank you...
0
 

Author Comment

by:Angela_Wilcox
ID: 13720540
Well - live and learn - I learned I was being redundant - when you READ this sets the variables... since my file has varrying lengths - we combined the end of the file to ONE variable we called PERIODS... then we can read the file and skip the whole if loop... - apparantly matbiol, we do not need to be more explicit than telling it to "do" a series of commands until it is "done"

Here is what the final code looked like:
------------------------
while read TGAPP TGDB SRCAPP SRCDB CAT PERIODS

do

## echo to the logfile to verify they were set correctly

echo "Variables and Parm Settings"  >> "$LOGFILE" 2>&1

echo "TGAPP =" $TGAPP >> "$LOGFILE" 2>&1
echo "TGDB =" $TGDB >> "$LOGFILE" 2>&1
echo "SRCAPP =" $SRCAPP >> "$LOGFILE" 2>&1
echo "SRCDB = " $SRCDB >> "$LOGFILE" 2>&1
echo "CAT =" $CAT >> "$LOGFILE" 2>&1
echo "PERIODS = " $PERIODS  >> "$LOGFILE" 2>&1

##Create Replication

function runrepcycle1cmd
{
      /db2olap/bin/essmsh << END
      login $USER $PASSWORD on $SERVER;
      spool stdout on to '/db2olap/scripts/angietest/logs/repcycle1_stdout.txt';
      spool stderr on to '/db2olap/scripts/angietest/logs/repcycle1_stderr.txt';
      create replicated partition $SRCAPP.$SRCDB area '$PERIODS $CAT, @Levmbrs(ACT,0), @Levmbrs(AAT,0), @Levmbrs(ServTU,0), @Levmbrs(SubTU,0), @Levmbrs("Expense Product",0), @LevMbrs(Account,0), @Levmbrs(Center,0), @Levmbrs(Activity,0)' to $TGAPP.$TGDB at $SERVER as $USER identified by '$PASSWORD' using $USER identified by '$PASSWORD' for creation area '$PERIODS $CAT, @Levmbrs(ACT,0), @Levmbrs(AAT,0), @Levmbrs(ServTU,0), @Levmbrs(SubTU,0), @Levmbrs("Expense Product",0), @LevMbrs(Account,0), @Levmbrs(Center,0), @Levmbrs(Activity,0)' update allow;
      spool off;
      exit;
END
}

echo "run the repcycle1cmd function" >> "$LOGFILE" 2>&1

runrepcycle1cmd;

echo "refresh replicated partition $SRCAPP.$SRCDB to $TGAPP.$TGDB at $SERVER all data;"|essmsh -l $USER $PASSWORD -i

done < /db2olap/scripts/angietest/CreateReplicationCycle1.txt
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question