While Loop not running

echo "The recreate was successfully completed for device file $LCL_CLN_FILE." >> $LOG_FILE
   remaining=$(symclone -sid $LCL_SID -f $ETC/$LCL_CLN_FILE query | grep MB | awk '{print $2}')
if [ $remaining -ne 0 ]
   then
   while [ $remaining -ge 1 ]
   do
           echo "$remaining MB's to be copied........." >> $LOG_FILE
           sleep 500
           remaining=$(symclone -sid $LCL_SID -f $ETC/LCL_CLN_FILE query | grep MB | awk '{print $2}' | sed 's/[.].*//')
  done
else
   echo "DATA is already copied" >> $LOG_FILE
fi

I get a value for remaining, but when I run this the script is sleeping and comming out of while loop, what I am doing wrong?

Why are the lines which populate $remaining different? One has a "sed", one doesn't.

What does the raw line contining Mb look like?

Question should be what value you get at what step. Maybe you add an echo $remaining at the points where you issue that symclone to see what it is actually doing.

Also I guess you could leave out the initial if -condition, as the while -loop already checks the status and -ge 1 must be true - else it would not reach the while -loop. So just the while -loop should be sufficient in terms of control.

Methyl,

I can add sed to the other line, I missed it.

remaining=$(symclone -sid $LCL_SID -f $ETC/LCL_CLN_FILE query | grep MB | awk '{print $2}' | sed 's/[.].*//')

I get an integer value assigned to "remaining" variable as an output of the command.

---------- Post updated at 10:37 AM ---------- Previous update was at 10:22 AM ----------

Zaxxon,

I will try to implement the changes that you suggested.

The output right now is as follows:-

 
The recreate was successfully completed for device file GSI_REPORTING_PAIRS.
1921291 MB's to be copied.........
 
'Activate' operation execution is in progress for the device list in
device file '/usr/local/scripts/emc/backup/etc/GSI_REPORTING_PAIRS'. Please wait...
 
 

Right now it goes in to the

 while [ $remaining -ge 1 ] 

loop and just comes out of it . The activate operation should actually be done after

  $remaining  

reaches less than 1

I also get an error saying argument missing, not sure if it makes sense

For which command, it is showing argument missing ?

may be in some point of loop, the grep command may fails to give the filename to the awk command.

symclone -sid $LCL_SID -f $ETC/LCL_CLN_FILE query | grep MB

Ok, please add a set -x at the beginning of that code snippet and set +x at the end of it and rerun. Then post the output please.

Based on the data sample, isn't the number the first field? On my test the first value of $remainder is the string MB's which might explain your syntax error.

awk '{print $1}'

Also, the "sed" appears to be pointless.

Sorry Guys It was my silly mistake that caused the error.

Zaxxon,

Putting set -x helped to troubleshoot the problem that it was not able to open "LCL_CLN_FILE " as I did not use

$LCL_CLN_FILE
 
remaining=$(symclone -sid $LCL_SID -f $ETC/LCL_CLN_FILE query | grep MB | awk '{print $2}' | sed 's/[.].*//')
 

Methyl,

I get the MB's value as floating number sometimes so I am using the sed part to remove the decimal part

I am new to scripting and trying to learn it so apologize for not being clear with my questions.

But it's still $1 not $2 ??

Methyl,

The first field is MB's itself.

 
symclone -sid XXX -f YYY query | grep MB
  MB(s)              9999.0      0.0                     0.0

the output of the command after grep, awk '{print $1}' gives MB, while $2 gives 9999.0

Ah, the example in Post #8 is quite different.