-1

I want to run some jobs after waiting some time:

I can do:

sleep 1000;foo-1;foo-2

What I expected is to wait couple of hours, sleep seems not the best solution.

and I don't want to setup cron job.

Mark K
  • 779
  • 2
  • 13
  • 33
  • 1
    [GNU sleep](https://www.gnu.org/software/coreutils/manual/html_node/sleep-invocation.html) accepts [`inf`](https://www.gnu.org/software/coreutils/manual/html_node/Floating-point.html#Floating-point). Which `sleep` are you using? – muru Jul 27 '21 at 03:56
  • should be /bin/sleep, I use it directly in the shell. – Mark K Jul 27 '21 at 04:04
  • 2
    You may not want a cron job. But have you considered `at` ? – user10489 Jul 27 '21 at 05:03
  • I didn't know this before, looks good. – Mark K Jul 27 '21 at 05:11
  • @user10489, you should write an answer :-) – pLumo Jul 27 '21 at 07:15
  • 1
    Does this answer your question? [Shell: is it possible to delay a command without using \`sleep\`?](https://unix.stackexchange.com/questions/482725/shell-is-it-possible-to-delay-a-command-without-using-sleep) – muru Jul 27 '21 at 07:26
  • 2
    Why do you think that _sleep seems not the best solution_? – Arkadiusz Drabczyk Jul 27 '21 at 07:54
  • 1
    What is your question? The title asks for how long one may sleep with `sleep`, while the body of the question seems to ask for something else. – Kusalananda Jul 27 '21 at 08:11

1 Answers1

3

POSIX states:

As with all other utilities that take integral operands and do not specify subranges of allowed values, sleep is required […] to deal with time requests of up to 2147483647 seconds.

(source)

2147483647 seconds is over 68 years. Implementations are allowed to support larger numbers. Unless your OS is extremely obscure, you can expect your sleep to be able to reliably sleep for up to about 68 years.

What if your OS is extremely obscure? Consider a hypothetical implementation of sleep that is limited to 16-bit signed integer. The maximum value would be 32767 seconds, it's over 9 hours. Even this sleep would be able to wait "couple of hours".

I can imagine even more limited sleep. 8-bit values would allow at most 255 (if unsigned) or 127 (if signed) seconds. It's literally a couple of minutes. I doubt anyone ever implemented so limited sleep.

The conclusion is: to wait couple of hours, sleep is a decent solution. Technically it will work.

Kamil Maciorowski
  • 19,242
  • 1
  • 50
  • 94