Sleep Until Query


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sleep Until Query
# 8  
Old 01-13-2012
How about this
Code:
                                          
#!/bin/bash                               
STOP=`echo 14 \* 3600 + 0 \* 60 |bc`      
START=`echo 20 \* 3600 + 10 \* 60 |bc`    
echo $$ >proc.pid                         
while [ -r proc.pid ]                     
do                                        
H=`date +%H`                              
M=`date +%M`                              
SECONDS=`echo $H \* 3600 + $M \* 60 |bc`  
if [ $SECONDS -gt $STOP ]                 
then                                      
        DIFF=`echo $START - $SECONDS |bc` 
        if [ $DIFF -gt 0 ]                
        then                              
                echo $DIFF                
                #sleep $DIFF              
        fi                                
fi                                        
echo Done `date`                          
sleep 5                                   
done

# 9  
Old 01-14-2012
Reference post #5.
Quote:
while [ $curr_time -ge $time7pm and $curr_time -le $time630am ]
The reason the script did not exit is because the "and" condition is incorrect.
Should have been:
Code:
while [ $curr_time -ge $time7pm -a $curr_time -le $time630am ]

But there is a design issue with using integer comparisons with HHMM fields because the leading zero disappears for hours less than 10. Mathematically this in itself would not be an issue if we had 100 minutes to the hour - but we don't!


jgt's IDEA is much better (but the script has problems). Do integer comparision in whole minutes (not seconds unless you need that accuracy).
I can't see how that script gets out of the while loop. Personally I would use "while true" and then the "break" command to get out of the while loop when the condition is met.

Last edited by methyl; 01-14-2012 at 06:02 PM.. Reason: removed wrong assumption
# 10  
Old 01-14-2012
I guess I should have added more detail.
The script runs until proc.pid is deleted by some other process.
Since we didn't have the complete original script there was no explanation of how the script ever ends. The OP asked that his script run continuously but not between 2pm and 4pm.
He should comment the echo $DIFF, and un-comment the sleep $DIFF lines, and replace "echo Done `date`, sleep 5" with his own script.
Once this is done, his original script will execute repeatedly until 2pm at which point it will sleep (approximately 7200 seconds) until 4pm, and then continue.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sleep while i > 0

Hi, I have a script that runs a process at the beginning and I want to sleep/wait until this process is finished and then continue with the rest of the script. I am trying with this, but it is not working: process=`ps -ef | grep "proc_p01 -c" | grep -v grep | wc -l` if ; do sleep 10 done... (7 Replies)
Discussion started by: apenkov
7 Replies

2. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

3. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

4. Shell Programming and Scripting

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way: How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies

5. HP-UX

sleep & localtime query

Hi, I work on HPUX application and i had a query regarding the sleep & localtime system call in HPUX. Here is the code that we have : const uint32_t WAKE_INTERVAL_SEC(30*60); while (true) { // Find out what time it is time(&currentTime);... (3 Replies)
Discussion started by: nsvora
3 Replies

6. Shell Programming and Scripting

add the output of a query to a variable to be used in another query

I would like to use the result of a query in another query. How do I redirect/add the output to another variable? $result = odbc_exec($connect, $query); while ($row = odbc_fetch_array($result)) { echo $row,"\n"; } odbc_close($connect); ?> This will output hostnames: host1... (0 Replies)
Discussion started by: hazno
0 Replies

7. UNIX for Dummies Questions & Answers

Sleep less than 1 second

Does anyone know a way to sleep less than 1 second? Sometimes when I write scripts that iterates a loop many times it would be nice to slow things down, but sometimes 1 second is too much. (9 Replies)
Discussion started by: bjorno
9 Replies

8. Shell Programming and Scripting

Sleep under one second

If I want a script to sleep for less than a second, would I use a decimal? In other words, if I wanted my script to sleep for 1/4 of a second, would I say, SLEEP .25 ?? (5 Replies)
Discussion started by: Scoogie
5 Replies

9. UNIX for Dummies Questions & Answers

sleep

what is the purpose of the sleep command? (5 Replies)
Discussion started by: Anna
5 Replies
Login or Register to Ask a Question