1

systemd has timers with lots of useful ways to input dates or times. I'm writing a long running data processing script. Is there any command to sleep until a specific systemd time definition occurs? e.g. systemd-timer-sleep --until-calendar="03:00", a commmand which would block until the next 3:00am.

Yes, I know this means my script might run for days, that's OK.

I'm sure I can do this with date & sleep & calculating the number of seconds until my desired datetime, but I want to know if there's (now) an easier way.

Amandasaurus
  • 31,471
  • 65
  • 192
  • 253

1 Answers1

0

I think the easiest way to achieve this would be something like the following:

while [ $(date +%H:%M) != "03:00" ]; do sleep 1; done

This will block until the next time it is 3 AM. You can pretty easily modify the format codes to be whatever you'd like.