1

I've been looking for a quick and easy way to verify if my site was up and if not to do something about it by running another batch file.

I found one or two "solutions", but none of them work and they all seem way too complicated batch scripts for such a seemingly simple task.

From what I see, either ping should be used, or alternatively installing wget or something similar would be required.

I actually managed to find a quick way to check this with node.js, but then was unable to find an easy way to run a batch file in case the website is down. So I think a pure batch solution is probably a better way to go...

Predrag Stojadinović
  • 3,439
  • 6
  • 34
  • 52
  • I think the code in the O.P.'s question on [this page](http://stackoverflow.com/q/15395490/1683264) is the answer. (It wasn't the answer to his question, but I think it is to yours.) – rojo Mar 06 '15 at 14:10

1 Answers1

2

After a lot of trial and error, I found what I consider an acceptable solution. Namely, I am downloading a single file from my website using wget, then checking if that file exists as an indication if the website is available. I am using the favicon.ico file here, since it is so small. Also, I am restricting wget to only one try and forcing it to give up after 5 seconds since that is more than enough for such a small file.

del favicon.ico
wget -N --tries=1 --timeout=5 "http://example.com/favicon.ico"

if exist favicon.ico (
    echo [All is good]
) else (
    some-other-batch-file.bat
    echo [Website down]
)
del favicon.ico
Predrag Stojadinović
  • 3,439
  • 6
  • 34
  • 52
  • What if a website doesn't have a favicon? Could still be up but have no favicon – mbx-mbx Mar 06 '15 at 13:07
  • 1
    @Magrangs the question is about checking your own website, so you should know what is available if the favicon is not... – Predrag Stojadinović Mar 07 '15 at 13:16
  • Maybe the title should be changed from "How to check if website is available" which is quite generic to "How to check if your website is available". – mbx-mbx Mar 07 '15 at 20:20