0

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
  • 865
  • 3
  • 14
  • 40

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.