Skip to content

Instantly share code, notes, and snippets.

@Himura2la
Last active April 15, 2022 11:01
Show Gist options
  • Save Himura2la/62af8240d7f0df3973873a63dee1ff82 to your computer and use it in GitHub Desktop.
Save Himura2la/62af8240d7f0df3973873a63dee1ff82 to your computer and use it in GitHub Desktop.
#!/bin/sh
url='https://httpstat.us/500'
attempts=3
delay_sec=3
curl_return_code=1
while [ $curl_return_code -ne 0 ] && [ $attempts -gt 0 ]
do
echo "--- requesting..."
result=$(curl --fail --silent --show-error --max-time 120 --get "$url")
curl_return_code=$?
attempts=$((attempts-1))
echo "--- return code: $curl_return_code | attempts left: $attempts"
[ $curl_return_code -ne 0 ] && sleep $delay_sec
done
if [ $curl_return_code -ne 0 ]
then
echo "--- failed!" 1>&2
else
echo "--- success! $result"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment