Reputation:
I need a cronjob, that check if a page is running. I think by check if the HTTP response status code is "200".
If the status code is not "200" a bash code must be executed.
I hope someone can help me with this topic. I tried it by myself but I have no idea how to get the code working.
Upvotes: 1
Views: 686
Reputation: 684
You can use it like..
#!/bin/bash
status_code=$(curl --write-out %{http_code} --silent --output /dev/null https://www.my-site.com/)
if [[ "$status_code" -ne 200 ]] ; then
## do your stuff here
echo "Site status changed to $status_code"
else
exit 0
fi
Upvotes: 2