I would like to run a command and then check the results for the string "200 OK".
So far, I have the following bash script:
for i in $(seq 1 50)
do
printf "i is: $i\n"
RESULTS="$(curl -i -H "Accept: application/json" -X GET http://localhost/test/store/widget/123 | grep -ne "200 OK")"
if [ $RESULTS -eq 0 ]; then
echo "GET failed with $RESULTS"
break
else
echo "we're good"
fi
done
When I run the above script, I get the following results:
i is: 1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 85 100 85 0 0 3944 0 --:--:-- --:--:-- --:--:-- 4047
gettest.sh: 8: [: 1:HTTP/1.1: unexpected operator
we're good
i is: 2
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 85 100 85 0 0 3293 0 --:--:-- --:--:-- --:--:-- 3400
gettest.sh: 8: [: 1:HTTP/1.1: unexpected operator
we're good
The output that I get back from running the curl command once looks like this:
HTTP/1.1 200 OK
Date: Tue, 10 Feb 2015 13:21:18 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.5
Content-Length: 85
Content-Type: application/json; charset=utf-8
{"status":pass,"widgetinfo":"{\"widgetname\":\"the best widget\",\"price\":\"100.00\"}"}
Based on the above results, I have a few questions:
- Why does the bash script print the stats about total time, speed etc to get the results from curl?
- how should I modify the script so that unless the script fails, I only want to see the counter value (i), and a status indicating a pass. If it fails, I want the script to exit with the details of what was returned by the curl command.
- why am i getting the error
gettest.sh: 8: [: 1:HTTP/1.1: unexpected operator?
Any tips? Thanks!