While Loop not running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While Loop not running
# 1  
Old 03-26-2012
While Loop not running

Code:
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?


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by rajsan; 03-26-2012 at 11:00 AM.. Reason: code tags, see PM
# 2  
Old 03-26-2012
Why are the lines which populate $remaining different? One has a "sed", one doesn't.

What does the raw line contining Mb look like?
# 3  
Old 03-26-2012
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.
This User Gave Thanks to zaxxon For This Post:
# 4  
Old 03-26-2012
Methyl,

I can add sed to the other line, I missed it.
Code:
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:-

Code:
 
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
Code:
 while [ $remaining -ge 1 ]

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

reaches less than 1

I also get an error saying argument missing, not sure if it makes sense
# 5  
Old 03-26-2012
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.

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

# 6  
Old 03-26-2012
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.
# 7  
Old 03-26-2012
Quote:
awk '{print $2}'
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.
Code:
awk '{print $1}'

Also, the "sed" appears to be pointless.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running in a loop in UNIX

I have a table in oracle which has 2 columns table_name table_name1 U1 T1 U2 T2 I have to take these as a variable in unix and then go to /home/bin and execute a unix command using these variables. Considering that there is only one row in the table I was able to write the below but need help... (2 Replies)
Discussion started by: Ashcalin
2 Replies

2. Shell Programming and Scripting

While loop is running only for the first iteration

Hello, I've written a script to automate encoding of all the MP4 files in a directory (incl. subdirectories). But unfortunately it's running for the first MP4 file only. My machine details: root@Ubuntu16:~# uname -a Linux Ubuntu16 4.10.0-28-generic #32~16.04.2-Ubuntu SMP Thu Jul 20 10:19:48... (2 Replies)
Discussion started by: prvnrk
2 Replies

3. Shell Programming and Scripting

Running awk and while loop on data

so this is what i want to do. i have data that looks like this: DATA: Array: A Interface Type: SAS Unused Space: 0 MB Status: Failed Logical Drive: 2 Size: 279.4 GB Fault Tolerance: RAID 1 Heads: 255 Sectors Per Track: 32... (2 Replies)
Discussion started by: SkySmart
2 Replies

4. Shell Programming and Scripting

Help Running Loop Script

Hi I have a file called lastlogin_1 that contains a list of usernames. I would like to put together a quick loop script that will use a variable (the contents of lastlogin_1 file) and grep all directories and sub directories in the current directory (/in/the/current/directory) for each username... (3 Replies)
Discussion started by: jamba1
3 Replies

5. Shell Programming and Scripting

Running for loop on remote server

Hi, I'm having a problem performing for loop on remote server, i know this can be done with one liner but i'm not sure how it works if using logical operator such as for ifs and case or while for server in sterverA serverB serverC ; do ssh -v $server "cd ~/MyDocuments/; bag=`find... (6 Replies)
Discussion started by: sexyTrojan
6 Replies

6. Shell Programming and Scripting

For loop and running 2 commands at once?

HI. I am trying to run 2 commands, using the "for x in a b c d" loop but i am having a hard time coding it... Here is what i have so far: for SERVER in SERVERA SERVERB SERVERC SERVERD SERVERE do ############################################################################### #... (5 Replies)
Discussion started by: Stephan
5 Replies

7. Shell Programming and Scripting

loop when process running

Hi Gurus, Could you please help me to create a shell script that will be started by a cron job once every night at 24.00 h (that should bee easy:)) The shell script should control every 30 seconds the name of a process, and when the process doesn't run anymore it should execute a few further... (12 Replies)
Discussion started by: blackwire
12 Replies

8. UNIX for Dummies Questions & Answers

until loop : running even if condition is satisfied

I am checking one until loop with the following logic until || |||| do sleep 30 done before running this i am exporting above variables to SUCCESS.But the loop is running in infinite loop.My requirement is to make the loop run until all the 3 variables are SUCCESS or any of the 3... (2 Replies)
Discussion started by: dr46014
2 Replies

9. Shell Programming and Scripting

running a batch file in loop

i have a batch file which should run every five min...for an hour can any one help me out (1 Reply)
Discussion started by: aemunathan
1 Replies

10. Shell Programming and Scripting

running command in while loop

I have a script that users a while read, whithin this I want to execute the cp -i command on some of the results, however because it is in a loop it skips the -i part of cp. How do I get the loop to stop each time cp -i is run and wait for the user to type the response. (2 Replies)
Discussion started by: gefa
2 Replies
Login or Register to Ask a Question