Loop check


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Loop check
# 1  
Old 07-17-2009
Loop check

Hi Gurus
I have a recquirement where my loop should work if i have more than 4 listed files in a particular directory.
Like the loop in while should continue checking if the directory has more than 4 files and should exit after there are 4 or more files ; if not more than 4 files it should continue checking the number of files

Need help for achieving this scenario

Code:
cd /export/home/e299821/rohan
linecount=`ls -ltr | wc -l`
a=0
echo $linecount
echo $a
while [[ $a = 0 ]]
do
if [ $linecount -gt 3 ]
then
echo $lineocunt
a=`expr $a + 1`
echo "loop completed"
fi
done


Last edited by vgersh99; 07-17-2009 at 08:47 AM.. Reason: code tags, PLEASE!
# 2  
Old 07-17-2009
Are you looking for something like this:

Code:
while [ $(ls -1|wc -l) -lt 5 ]
do
        echo 'in loop'
done
echo 'out loop'

# 3  
Old 07-17-2009
this loop shall execute only 4 or max 5 times ... i want that my loop should do the following

varA = 4
varB=8

while [[ varA -ne varB]]
do
check for value of varA till both are equal .
if equal " loop complete " exit
done
# 4  
Old 07-17-2009
r_t_1601, I couldnt understand your requirement. You want a while loop to poll in a directory to check if the folder has more than 4 files and if yes the loop.

Isnt my code doing that?
# 5  
Old 07-17-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 6  
Old 07-17-2009
Quote:
Originally Posted by r_t_1601
this loop shall execute only 4 or max 5 times ... i want that my loop should do the following

varA = 4
varB=8

while [[ varA -ne varB]]
do
check for value of varA till both are equal .
if equal " loop complete " exit
done
The while condition will compare, why you need both if and while?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check two condition in while loop

Hi, I Have to check two condition in while loop every 2 minutes. while loop is accompanied with number of times it will check.Please help in putting the two condition in while loop as appropriate. z= input value, A=1 while do 1.check the file output,if the file output is N then keep on... (2 Replies)
Discussion started by: netdbaind
2 Replies

2. Shell Programming and Scripting

While Loop to Check for Integer

Hello All, In ksh I am trying to ensure that user inputs are integers otherwise redisplay prompt with the following code; a=0 b=0 c=0 read b?"Please enter a number: " read c?"Please enter another number: " while ] && ]; do read b?"Not a number. Please enter a number: " read c?"Not... (4 Replies)
Discussion started by: techieg
4 Replies

3. Shell Programming and Scripting

IF loop to check the time modified

Hi Frnds, i have a folder test in which files generated daily how to chek the files that are modified on that day as a condition for ex, if then echo "i have got something to do with the file" else echo" sorry" fi i will have more than 3 to 4 files that are modified today. and if... (5 Replies)
Discussion started by: mahesh300182
5 Replies

4. UNIX for Dummies Questions & Answers

For loop to check the files availability

Hi, I need a help with my script. Below is my script. What I am doing here is finding the date of the file which I need to process and then finding the list of file names. Based on the list of file names, check has to be done to see if all the files are there and log the details to a error... (3 Replies)
Discussion started by: Vijay81
3 Replies

5. Shell Programming and Scripting

Check condition inside the loop

Hi, I am in trouble. I can get inside my condition test inside a loop : I am in ksh (solaris) while read file do <commande to retrieve file> >> ${LOG_RETRIEVE_FILE.log} msg_err=$(cat ${LOG_RETRIEVE_FILE.log} | grep "error retrieve") if ; then <sendmail> exit 1 fi done I tried... (6 Replies)
Discussion started by: Aswex
6 Replies

6. Shell Programming and Scripting

WHILE LOOP CONDITION CHECK

Hello I want to compare values of two variables as CHECK condition in a while loop. eg: var1=0 var2=10 while do echo " $var1 " var1=`expr $var1 + 1` done However this is giving error.How to do it in a proper manner? Thanks. (3 Replies)
Discussion started by: dashing201
3 Replies

7. Shell Programming and Scripting

loop and check

Hi, We are doing a process manually and i am trying to automate it. This is the process. We have a set of files in the directory /temp/d1. the number of files are dynamic. For ex: if i have 5 files i want to compare the chatacters 45-58 of the last line of the first file with the same... (2 Replies)
Discussion started by: dnat
2 Replies

8. Shell Programming and Scripting

Check for statup process in loop?

I've written a script to check for Oracle's listener, eventman and pmon processes however there are several databases that startup which can take several minutes. I'd like to add code to my current script that greps for the process “startup” and whether its condition is true or false. If the... (1 Reply)
Discussion started by: dataciph3r
1 Replies

9. Shell Programming and Scripting

Loop to check for file up to 3 times

Please forgive this I think rather basic question. I have been away from UNIX for a very long time and am in need of some help. I need to be able to check for the existance of a specific file name say 'file.dat' in a particular location If the file exists then run a second process (at... (2 Replies)
Discussion started by: JohnCrump
2 Replies

10. Shell Programming and Scripting

looking for help with a dd loop check script

Hi Can anyone please help with the following script I need - .ksh preferably? I have external disks attached to a system that I have to label and then run the dd command on all external disk found. I have kicked off the dd command as follows manually to see what its output is like first... (1 Reply)
Discussion started by: angusyoung
1 Replies
Login or Register to Ask a Question