Alex Rivera | Logout

Sleep until a specific time/date

Asked 2009-03-14T14:36:03.167
141

I want my bash script to sleep until a specific time. So, I want a command like "sleep" which takes no interval but an end time and sleeps until then.

The "at"-daemon is not a solution, as I need to block a running script until a certain date/time.

Is there such a command?

Edit
Report

2 Answers

1

You could perhaps use 'at' to send a signal to your script, which sat waiting for that signal.

answered 2009-03-14T15:09:17.440
0

Here's something I wrote just now to synchronise multiple test clients:

#!/usr/bin/python
import time
import sys

now = time.time()
mod = float(sys.argv[1])
until = now - now % mod + mod
print "sleeping until", until

while True:
    delta = until - time.time()
    if delta <= 0:
        print "done sleeping ", time.time()
        break
    time.sleep(delta / 2)

This script sleeps until next "rounded" or "sharp" time.

A simple use case is to run ./sleep.py 10; ./test_client1.py in one terminal and ./sleep.py 10; ./test_client2.py in another.

answered 2013-06-11T12:41:05.297

Your Answer