• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1841
  • Last Modified:

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

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
Angela_Wilcox
Asked:
Angela_Wilcox
  • 2
1 Solution
 
mathbiolCommented:
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
 
Angela_WilcoxAuthor Commented:
I am not sure whether it will or not - but will give it a try and post the results... Thank you...
0
 
Angela_WilcoxAuthor Commented:
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now