Jump to content

unix while loop help


mettastar

Recommended Posts

I need to wait for a n number of files to appear before coming out of the loop. filename will be wildcard

files unnayo levo teluskodaniki i figured it out.. but naku certain number of files untene proceed avvadam elano teliyatle..

my current logic 

while [ ! -f #Path#/Temp/Trigger_#Tag#_* ]; do sleep 2 ; done ; echo 0

 

but naku files equal to certain number untene povali ante etlaa..

Link to comment
Share on other sites

30 minutes ago, mettastar said:

I need to wait for a n number of files to appear before coming out of the loop. filename will be wildcard

files unnayo levo teluskodaniki i figured it out.. but naku certain number of files untene proceed avvadam elano teliyatle..

my current logic 

while [ ! -f #Path#/Temp/Trigger_#Tag#_* ]; do sleep 2 ; done ; echo 0

 

but naku files equal to certain number untene povali ante etlaa..

    @yomama  ki message cheyi bro ..... he may help you 

Link to comment
Share on other sites

Probably not a sophisticated way but this will do what you are looking for

 

#!/bin/ksh

matcond=1
descount=10 ##assuming you need 10 files
while [ $matcond == 1 ]
do
ls -ltr *touch* > tempfile
count=$(wc -l < tempfile)
echo $count
if [ $count -eq $descount ]
then matcond=2
else
sleep 2
fi
done

Link to comment
Share on other sites

got it 

 

while [ ! -f /Temp/Trigger_* ] || [ -f /Temp/Trigger_* ] && [ "$( ls /Temp/Trigger_* 2> /dev/null | wc -l)" -le "2" ]; do echo sleeping ;sleep 2 ; done ; echo 0

 

evarikain use aithadi
 

Link to comment
Share on other sites

1 minute ago, mettastar said:

got it 

 

while [ ! -f /Temp/Trigger_* ] || [ -f /Temp/Trigger_* ] && [ "$( ls /Temp/Trigger_* 2> /dev/null | wc -l)" -le "2" ]; do echo sleeping ;sleep 2 ; done ; echo 0

 

evarikain use aithadi
 

yourock 

Link to comment
Share on other sites

3 hours ago, Tesla said:

Probably not a sophisticated way but this will do what you are looking for

 

#!/bin/ksh

matcond=1
descount=10 ##assuming you need 10 files
while [ $matcond == 1 ]
do
ls -ltr *touch* > tempfile
count=$(wc -l < tempfile)
echo $count
if [ $count -eq $descount ]
then matcond=2
else
sleep 2
fi
done

Dont want to write a script bro.. inline lo chedham ani. i got it. thanks though

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...