Get Linux Website Status Code

I have a small vps where I host a web application that I developed and it starts to get a lot of visits.

I need to check / check something, every X minutes, to check if the website is working (check the status code, 200) or if it is turned off (code 500) and if it is turned on, restart the script that I run made to restart some services.

Any idea how to test this on Linux? Curl, Lynx?

+3
source share
4 answers

Ok, I created two scripts:

  • site-statush.sh http://yoursite.com => to check the status of the site, and if 200, do nothing, else call services-action.sh restart
  • services-action.sh restart = > , , $services

https://gist.github.com/2421072

-1
curl --head --max-time 10 -s -o /dev/null \
    -w "%{http_code} %{time_total} %{url_effective}\n" \
    http://localhost

10

Curl 28, ( $?)

+2

man .

curl .

, , , , - -w http-code variable.

EDIT:

, . @Ken , -w.

+1

All Articles