exit out of a while loop with error

im running a while loop as a file watcher, with incremental counter on the retries..however when the retries reach it's limit i want it exit and echo and error and stop the batch. Im not sure the code i have will do that already...

Here is what i have that works:

#!/usr/bin/ksh
count=0
while [ $count -lt 3 ]
do
count=`expr $count + 1`
echo "Try $count"
RUNDATE=`date "+%h%e"`
filedate=`xyz.txt | awk '{print $6,$7}`
if [ "$Spotfiledate" != "$RUNDATE" ]
then
echo "File's date is $Spotfiledate and today's date is $RUNDATE. They don't match"
echo "I will sleep 30 seconds and try again; 3 tries is my limit"
sleep 30
else echo "Today's file $Spotfiledate is now in."
echo "Sleeping 30 secs to allow it to process."
sleep 30
break
fi

done

Exit with 0 if the try is Ok.

Just put a comment after the loop, meaning all retries have been done.

#!/usr/bin/ksh
count=0
while [ $count -lt 3 ]
do
   count=`expr $count + 1`
   echo "Try $count"
   RUNDATE=`date "+%h%e"`
   filedate=`xyz.txt | awk '{print $6,$7}`
   if [ "$Spotfiledate" != "$RUNDATE" ] 
   then 
       echo "File's date is $Spotfiledate and today's date is $RUNDATE. They don't match"
       echo "I will sleep 30 seconds and try again; 3 tries is my limit"
       sleep 30 
   else echo "Today's file $Spotfiledate is now in."
       echo "Sleeping 30 secs to allow it to process."
       sleep 30   # maybe this sleep is not necessary
       exit 0
    fi
done
echo "Error, maximum number of retries reach!!"

The loop will exit when it reaches the maximum. Print your error message after the loop and exit with an error.

Please put code inside

 tags.


#!/usr/bin/ksh
count=0
while [ $count -lt 3 ]
do
    count=`expr $count + 1`

[/quote]

[indent]
You don't need an external command to do intergerr arithmetic:

count=$(( $count + 1 ))

Are you trying to execute a text file? Or did you mean to pipe it into awk?

filedate=$(awk '{print $6,$7}' xyz.txt )

But you don't need awk for that:

read a b c d e f g h < xyz.txt
filedate=$f$g

Where have you defined Spotfiledate?