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?

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top