There are a lot of way to do this.
Trying a certain number of times -
for c in {1..5}; do curl -s localhost:10100/status | grep -o "Tardis service is fully functional." && break; done
Obviously, you could add a sleep in that loop if you want to space them out a bit, but curl gives it a couple second before timing out by default, and you could adjust that too.
If you want a specific time limit instead of a certain number of attempts -
limit=10; start=$SECONDS;
until (( limit < (SECONDS-start) )); do
curl -s localhost:10100/status | grep -o "Tardis service is fully functional." && break
done
I assume just checking curl's return value isn't sufficient, because the service might successfully respond with a message other than I'm up?
If you want a more robust check on which you can base subsequent action -
chkStatus() {
local url="${1:-localhost:10100/status}"
local msg="${2:-Tardis service is fully functional.}"
local limit=${3:- 10} # can use this sort of setup with either logic
local pause=${4:- 1}
local ret=1 # assume fail, reset for success on a hit
local _ # only using as a counter
for _ in $(seq $limit); do
if curl -s "$url" | grep -o "$msg"; then ret=0; break; fi
sleep $pause
done
return $ret
}
chkStatus "$otherURL" "$otherMSG" "$otherLimit" "$otherPause" || echo FAIL
I turned on debugging output when I tested it -
$: set -x; chkStatus "$otherURL" "$otherMSG" "$otherLimit" "$otherPause" || echo FAIL; set +x
+ chkStatus google.com bogus 2 0.25
+ local url=google.com
+ local msg=bogus
+ local limit=2
+ local pause=0.25
+ local ret=1
+ local _
++ seq 2
+ for _ in $(seq $limit)
+ curl -s google.com
+ grep --color -o bogus
+ sleep 0.25
+ for _ in $(seq $limit)
+ curl -s google.com
+ grep --color -o bogus
+ sleep 0.25
+ return 1
+ echo FAIL
FAIL
+ set +x
$: set -x; chkStatus "$otherURL" "$otherMSG" || echo FAIL; set +x
+ chkStatus google.com 'The document has moved'
+ local url=google.com
+ local 'msg=The document has moved'
+ local 'limit= 10'
+ local 'pause= 1'
+ local ret=1
+ local _
++ seq 10
+ for _ in $(seq $limit)
+ curl -s google.com
+ grep --color -o 'The document has moved'
The document has moved
+ ret=0
+ break
+ return 0
+ set +x
Using full URL and a nonbogus message WITHOUT debug mode -
$: time chkStatus http://www.google.com/ CSS1Compat || echo "Google says no."
CSS1Compat
real 0m0.324s
user 0m0.015s
sys 0m0.154s
With a not-found message -
$: time chkStatus http://www.google.com/ "Anyone home?" 3 .5 || echo "Google says no."
real 0m2.580s
user 0m0.030s
sys 0m0.399s
Google says no.
(Note the success message comes before the time output as it's inside the function, but the fail message is after since it's not.)
Google does respond, but the function behaves accordingly if the requested message exists or doesn't.