I'm trying to test and quantify a intermittent error response from an http server. I have a curl call constructed that can make the necessary request, but I'm getting tired up typing up arrow and return.
How can I tell curl to repeatedly make the request until it encounters an error and then output the number of success responses before the error?
This bash recipe should do what you're looking for.
i=0 ; while true ; do curl -o /dev/null -s https://www.google.com/ ; if [ $? -ne 0 ] ; then echo $i ; break ; fi ; i=$(($i+1)) ; echo -en "$i \r" ; sleep 1 ; done
Broken out into multiple lines:
i=0 # set counter to 0
while true # infinite loop
do
curl -o /dev/null -s https://www.google.com/ # silent curl request to site
if [ $? -ne 0 ]
then
# curl didn't return 0 - failure
echo $i
break # terminate loop
fi
i=$(($i+1)) # increment counter
echo -en "$i \r" # display # of requests each iteration
sleep 1 # short pause between requests
done
You can optionally redirect cURL output to a file, so when it fails you can see the output using something like this:
curl -v -o /dev/null https://google.com &> /tmp/output.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With