The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
wait command - cat it wait for not-chile process? alex_5161 Shell Programming and Scripting 2 06-26-2008 06:14 PM
Sleep Command Glove Shell Programming and Scripting 1 10-03-2007 05:02 AM
wait / sleep what to use??? gkrishnag UNIX for Dummies Questions & Answers 1 09-19-2006 05:13 AM
Wait Command lesstjm Shell Programming and Scripting 1 03-28-2005 02:55 PM
Help with wait command ultraman Shell Programming and Scripting 1 10-21-2002 11:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-25-2008
nua7 nua7 is offline
Registered User
  
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 353
help in wait or sleep command

Hi All,
I have a script which runs 3 scripts. The first script creates two files. The other two scripts should run only when the files are created.

I tried the following for loop , but it is not working. Can someone please help me.


Code:
while [ ! -e script3.lck && script4.lck ]; do
# Sleep until file does exists/is created
sleep 1
done
  #2 (permalink)  
Old 09-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Your "and" conditional is wrong, you need to repeat the -e

Code:
while [ ! -e script3.lck -a ! -e script4.lck ]; do
The && goes between two commands, like this:

Code:
while [ ! -e script3.lck ] && [ ! -e script4.lck ]; do
or you could change the flow entirely, to avoid those pesky negations:

Code:
while true; do
  test -e script3.lck && test -e script4.lck && break
  sleep 1
done

Last edited by era; 09-25-2008 at 05:28 AM.. Reason: Sorry, misread the question at first
  #3 (permalink)  
Old 09-25-2008
nua7 nua7 is offline
Registered User
  
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 353
Thanks a lot era! But in this case, even if one file is created , the while loop ends. Ideally it should end if both the files exist.

Any idea, where I have gone wrong..?
  #4 (permalink)  
Old 09-25-2008
nua7 nua7 is offline
Registered User
  
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 353
whoops sorry for the confusion.. I tried your first suggestion, and it didn't work.

I tried your last suggestion, and works as a charm!!


Thanks a lot era!!!
  #5 (permalink)  
Old 09-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Sorry, I guess precedence problem, the negation covers the whole of the following expression even across an -a apparently. In other words, the second ! in the first solution is wrong, and should be taken out. Another reason to avoid pesky negations I suppose ...

Last edited by era; 09-25-2008 at 05:43 AM.. Reason: Take out the second !
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 12:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0