Help with sleep command:

Hi Frnz,

I need to execute sleep command but i dont know the definite time.
Let me put my req:

I am running one shell script and this script creates some lock file in temp dir ...now in my script i want one function to go into sleep mode till this lock file exists..one lock file gone that function should execute...

so can anyone tell me how can i put sleep command in some kind of loop..

Thanks:b:

Sorry for answering, even if i am not "frnz" (i do not think he is a member here):

sleep while lock-file exists:

print - "Waiting until file goes away: ....
while [ -e "/path/to/lock.file" ] ; do
     sleep 1
done
print - "File not there any more. Proceeding ..."

I hope this helps.

bakunin

thanx bakunin...well yes u r the frnz i was referring earlier :-)..

I need to add one more cond...i have one file i.e cdr_profile.txt...this file consisits of som hard coded values...now in my requirement after checkin lock i need to check if astro and ckm string is prenet in taht cdr_profile file..if it exists thn need to put sleep command untill lock file is there or sm other value comes other than ckm or astro..

can u plz help on this..
TIA..

---------- Post updated at 06:02 AM ---------- Previous update was at 06:02 AM ----------

thanx bakunin...well yes u r the frnz i was referring earlier :-)..

I need to add one more cond...i have one file i.e cdr_profile.txt...this file consisits of som hard coded values...now in my requirement after checkin lock i need to check if astro and ckm string is prenet in taht cdr_profile file..if it exists thn need to put sleep command untill lock file is there or sm other value comes other than ckm or astro..

can u plz help on this..
TIA..

Hello,

Per our forum rules, all users must write in English, use semi-formal or formal English language and style, and correct spelling errors.

The reason for this is that most software and operating systems are written in English and these are software related technical forums.

In addition, nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, you need to spell correctly!

So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your language, check your spelling and correct your spelling errors. You might receive a forum infraction if you don't pay attention to this.

Also, do not write in cyberpunk or abbreviated chat style under any circumstances and do not use profanity. This is not a chat room, it is a formal knowledge base to serve you and everyone, of all ages and cultural backgrounds.

Thanks!

The UNIX and Linux Forums

1 Like

Thank you, but probably i have to become more outspoken on this: we have a rule in place against using "leet speak" and the likes. If you expect me to put in the necessary effort to come up with a concise and correct answer i suppose i can expect you to put in the necessary effort not to save on a keystroke or two in return, yes? Please take into account that the people here are not freaks but hard working professionals. We maintain a professional tone here and expect others to do the same. Thank you for your consideration.

If you have to check for more than one condition just add these in your loop:

typeset -i continue=1

print - "waiting for all conditions to become false...."
while [ $continue -gt 0 ] ; do
     sleep 1
     (( continue = 0 ))
     if [ <condition1> ] ; then
          (( continue = 1 ))
     fi
     if [ <condition2> ] ; then
          (( continue = 1 ))
     fi
     if [ <condition3> ] ; then
          (( continue = 1 ))
     fi
     [...]
done
print - "all conditions turned false ...."

In your case you can check the condition of a certain keyphrase being in a file or not using grep .

I hope this helps.

bakunin

/PS: I only now see that Scrutinizer already mentioned it - i can only second what he said.

Thanks bakunin, for the solution you provided.

First of all, apologize for any inconvenience caused.

I will keep the points mentioned by you and Scrutinizer going forward in this forum.

Thanks again.

@ gnnsprapa: On this matter (behaviour) - dont ask for help in PM while the question is on the forum.
I dont search the other thread for you, so saying here.