help in wait or sleep command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help in wait or sleep command
# 1  
Old 09-25-2008
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  
Old 09-25-2008
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 06:28 AM.. Reason: Sorry, misread the question at first
# 3  
Old 09-25-2008
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  
Old 09-25-2008
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  
Old 09-25-2008
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 06:43 AM.. Reason: Take out the second !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In Shell Script Does Second Command Wait For First Command To Complete

Hi All, I have a question related to Shell scripting. In my shell script, I have following two commands in sequence: sed 's/^/grep "^120" /g' $ORIGCHARGEDAMTLIST|sed "s;$;| cut -f$FIELD_NO1 -d '|' | awk '{ sum+=\$1} END {printf (\"%0.2f\\\n\", sum/100)}' >$TEMPFILE mv $TEMPFILE $ORIGFILE... (3 Replies)
Discussion started by: angshuman
3 Replies

2. Shell Programming and Scripting

Sleep Command

Hello, Need a little help with the script below. I can't get it to sleep :( I'm trying to get this to check if the process is running and if it is, wait 10 secs and check again. Keep doing this until it's not running and then stop checking and send the email. #!/bin/ksh mailto=`cat... (2 Replies)
Discussion started by: bbbngowc
2 Replies

3. UNIX for Dummies Questions & Answers

sleep command off by a second

Hi Forum Im using sleep in a while loop goes around 10 times. i feed it a variable with the time i what it to sleep for eg sleep $sleepVal and then print system date and time to screen but sometimes 1 second is added to the time why is this here my code sleepVal=5 while do ... (3 Replies)
Discussion started by: ShinTec
3 Replies

4. UNIX for Dummies Questions & Answers

Help with sleep command

sleep 10 & Is this the write line of command to suspend 5 jobs for 10 minutes (6 Replies)
Discussion started by: senyor17
6 Replies

5. Shell Programming and Scripting

sleep command

Hi, Did the sleep command work for hours or only minutes just give description to work on my script waiting for the earliest response (5 Replies)
Discussion started by: thelakbe
5 Replies

6. UNIX for Dummies Questions & Answers

How can i use fork,sleep,wait and write in a process with father and son..??

Hi.. I was unable to do (gcc code) which refers to the fork,wait,sleep and write.. what i want to do: A process of father create (fork) a son and will sleep 90 seconds..After this, son process create a grandchild and will sleep 60 seconds..Grandchild process will sleep for 30 seconds..After... (3 Replies)
Discussion started by: gumlucin
3 Replies

7. UNIX for Dummies Questions & Answers

sleep command

Hi All I have a requiremnt to run a script inside another script. here i am pulling the record count from the table in oracle.If record count is greater than 0 the script is executed.The scripts updates the count in the table and again the count is found out and the condition is checked and same... (3 Replies)
Discussion started by: dr46014
3 Replies

8. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

9. Shell Programming and Scripting

Sleep Command

I am in need of some help; think I have confused myself. Here is the issue I am faced with. The script log file was fine, the nohup.out file has tens of thousands of lines like illegal use of sleep: sleep seconds So I assume there is something with the seconds calculation in the script... (1 Reply)
Discussion started by: Glove
1 Replies

10. UNIX for Dummies Questions & Answers

wait / sleep what to use???

Hi I have a script, where i need to execute the follwoing scripts/commands in my script. but those should be executed one by one cd /aa/205/jams .cmd/mass_all.sh - -> execution of this will take atleast 20-30mins cd $HOME/precompile ant-Ddir.location=$HOME/tomcat/webapps - -> execution of... (1 Reply)
Discussion started by: gkrishnag
1 Replies
Login or Register to Ask a Question