Created
April 9, 2018 11:08
-
-
Save sherwind/c9c69976e1337976b631410343b9118e to your computer and use it in GitHub Desktop.
bash function to retry command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
retry_cmd() | |
{ | |
attempts=15 | |
false | |
while [ "${?}" -gt 0 ]; do | |
if [ "${attempts}" -eq 0 ]; then | |
logger --tag "$0" -- "Failed to run $*: $output" | |
return | |
fi | |
logger --tag "$0" -- "Trying to run $*" | |
output=$("$@") | |
if [ "${?}" -gt 0 ]; then | |
let attempts-- | |
sleep 2 | |
false | |
fi | |
done | |
echo "${output}" | |
} | |
retry_cmd /path/to/command --arg1 arg1 --arg2 arg2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment