I need a bat script to check the availability of a tomcat service. I
thought about restarting tomcat if HTTP status code > 200 .. then I'd
just register that script as regular task, which in fact "monitors" my
service.
I googled to find out how to create web connections in a bat script, but
did not find much about it. Is this the common way doing this at all?
What would you prefer to keep a service alive?
Thanks for your comments
Henning
Use ping to see if it is responding?
--
Regards,
Mic
Yeah, thought about this, too. But ping tells only, if the server is up
and running. What I want is, to check if the context path to a website
is available. For example the URL
http://mydomain.com/context/path/
Some web logic knows how to react, when a user calls that URL and
responses with an HTTP status in the header. I'm interested in that
status to know, if the web logic has crashed. I'm not sure, if ping does
offer me such capabilities.
Henning
>Some web logic knows how to react, when a user calls that URL and
>responses with an HTTP status in the header. I'm interested in that
>status to know, if the web logic has crashed. I'm not sure, if ping does
>offer me such capabilities.
Here is a hybrid batch/JScript solution that doesn't require a third
party download ...
@set @x=0 /*
:: ChkHTTP.cmd
@echo off
setlocal
set "URL=http://www.google.com"
cscript /nologo /e:jscript "%~f0" %URL% | find "200" > nul
if %ErrorLevel% EQU 0 (
echo Web server ok % Put your code here %
) else (
echo Web server error reported
)
goto :EOF
JScript */
var x=new ActiveXObject("Microsoft.XMLHTTP");
x.open("GET",WSH.Arguments(0));x.send();
while (x.ReadyState!=4) {WSH.Sleep(50)};
WSH.Echo(x.status)
Thanks to '01MDM' for the concept.
_____________________
Tom Lavedas
You were given part of the usual solution - the tool to use but not how
to use it.
This pokes Yahoo and provided the one-line return:
wget --spider --no-verbose -t2 http://www.yahoo.com
2011-02-10 09:40:54 URL: http://www.yahoo.com/ 200 OK
The wget command line help switch is --help
Unfortunately, the report is sent to STDERR instead of STDOUT. I'm
pretty sure it returns an ERRORLEVEL.
--
Ted Davis (tda...@mst.edu)
That's what I thought of. I use wget to tell me if my home machine's IP
address has changed. I wrote a PHP script (on a free webhost) that takes as
its arguments an IP address, and then my home machine uses wget at every boot
to update the IP address:
wget -A zzz http://free.web.host/update.php?arg=ip.add.re.ss
('-A zzz' makes wget delete the downloaded file automagically.)
--
This manifesto has a single author.
A bit cleaner variation on the theme ...
@set @x=0 /*
:: ChkHTTP.cmd version 2
@echo off
setlocal
set "URL=http://www.google.com"
cscript /nologo /e:jscript "%~f0" %URL%
if %ErrorLevel% EQU 200 (
echo Web server ok
) else (
echo Web server error reported: %Errorlevel%
)
goto :EOF
JScript */
with(new ActiveXObject("Microsoft.XMLHTTP")){
open("GET",WSH.Arguments(0));send();
while(readyState!=4){WSH.Sleep(50)};
WSH.Quit(status)}
_____________________
Tom Lavedas
Then try cryping - from http://www.cryer.co.uk/downloads/cryping/ it lets
you "ping" a url for example:
cryping -http www.cryer.co.uk/downloads/cryping
and its free.
--
Brian Cryer
http://www.cryer.co.uk/brian
> Download
> http://users.ugent.be/~bpuype/wget/#basic
>
> Info
> http://en.wikipedia.org/wiki/Wget
Oh, great .. didn't know that wget is also available under windows :)
Thanks all for your help
/h