Skip to content
Latchkey

sleep: Usage, Options & Common CI Errors

sleep pauses the script for the given amount of time, then continues.

sleep is the simplest way to wait - for a service to boot, between retries, for eventual consistency. In CI it is also a smell: a fixed sleep wastes minutes and is flaky; poll instead.

What it does

sleep suspends execution for a duration. GNU sleep accepts fractional seconds and unit suffixes; it is used for backoff between retries and for crude waits on services that are coming up.

Common usage

Terminal
sleep 5                        # 5 seconds
sleep 0.5                      # half a second (GNU)
sleep 2m                       # 2 minutes (s/m/h/d, GNU)
# better than a blind sleep: poll until ready
until curl -fsS http://localhost:8080/health; do sleep 2; done

Options

ItemWhat it does
NSeconds (integer)
N.MFractional seconds (GNU)
Ns / Nm / Nh / NdSeconds/minutes/hours/days (GNU suffixes)
sleep a b cSum of all durations (GNU)

Common errors in CI

POSIX sleep takes only whole seconds - sleep 0.5 and suffixes like sleep 2m are GNU extensions and error on some BusyBox/BSD builds ("sleep: invalid number"). The bigger issue is design: a fixed sleep 30 either wastes runner minutes or is too short and flaky; replace it with a bounded poll (until ... do sleep 2; done with a timeout) so the job proceeds the instant the dependency is ready.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →