Question

Sometimes commands like apt-get update -q fail randomly in a cloudformation template user-data script. What's the proper way to retry them till they succeed?

Was it helpful?

Solution

As @shellter pointed out:

while ! apt-get update -q ; do sleep 1; done

Or, for a script:

while ! apt-get update -q
do
    echo "Failed. Trying again..." >&2
    sleep 1
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top