Watch a command until it succeeds

Bash

Retries every two seconds and stops the moment the command exits zero. Useful while waiting for a service to come up.

until curl -sf http://localhost:8080/health >/dev/null; do
  echo 'waiting for health check...'
  sleep 2
done
echo 'up'

More in Shell

Random picks