Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get website's status code in linux

I have a small vps where I host a web app that I developed, and it's starting to receive a lot of visits.

I need to check/verify, some how, every X minutes to see if the web is up and running (check for status code, 200) or if is down (code 500), and if down, then restart run a script that I made to restart some services.

Any idea how to check that in linux? Curl, Lynx?

like image 749
Alex Avatar asked May 15 '26 21:05

Alex


1 Answers

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

Times out after 10 seconds, and reports Response Code and time

Curl will exit with an error code of 28 if the request times out (check $?)

like image 67
Ken Avatar answered May 18 '26 10:05

Ken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!