我的问题是 ping 没有告诉我网站是运行还是关闭。我需要知道该网站是启动还是关闭。如果它没有启动,请重新启动脚本。如果有人能帮助我,那就太好了。
我唯一能想到的就是抓取网站内容,看看它是否正常。
我想用 Apatche Tomcat 在服务器上运行它。
@echo off
:first
PING -n 5 google.com | FIND "TTL" > nul
IF %errorlevel% == 0 (
echo Website is up.
goto :first
) ELSE (
echo Website is down. Restarting service
goto :second
echo restart
echo ping
)
:: This calls the second loop
:second
:: This will stop the service
net stop TapiSrv
ping -n 10 127.0.0.1
:: This will start the service
net start TapiSrv
:: This check to see if the website is up
GOTO :first
最佳答案
我把它拼凑在一起 - 它适用于 Win 8。
请注意,它会告诉您网站是否正在响应一条消息 - 它不会检查它所服务的页面是正常操作页面还是错误消息。
@echo off
if "%~1"=="" (
echo %0 www.url.com
echo Checks the status of the URL
pause
goto :EOF
)
>"%temp%\geturl.vbs" echo Set objArgs = WScript.Arguments
>>"%temp%\geturl.vbs" echo url = objArgs(0)
>>"%temp%\geturl.vbs" echo pix = objArgs(1)
>>"%temp%\geturl.vbs" echo With CreateObject("MSXML2.XMLHTTP")
>>"%temp%\geturl.vbs" echo .open "GET", url, False
>>"%temp%\geturl.vbs" echo .send
>>"%temp%\geturl.vbs" echo a = .ResponseBody
>>"%temp%\geturl.vbs" echo End With
>>"%temp%\geturl.vbs" echo With CreateObject("ADODB.Stream")
>>"%temp%\geturl.vbs" echo .Type = 1 'adTypeBinary
>>"%temp%\geturl.vbs" echo .Mode = 3 'adModeReadWrite
>>"%temp%\geturl.vbs" echo .Open
>>"%temp%\geturl.vbs" echo .Write a
>>"%temp%\geturl.vbs" echo .SaveToFile pix, 2 'adSaveCreateOverwrite
>>"%temp%\geturl.vbs" echo .Close
>>"%temp%\geturl.vbs" echo End With
cscript /nologo "%temp%\geturl.vbs" http://%1 url.htm 2>nul
if not exist url.htm (
echo site is down or access is denied
) else (
for %%a in (url.htm) do if %%~za GTR 0 echo site is up
del url.htm
)
del "%temp%\geturl.vbs"
pause
关于apache - 用于判断网站是启动还是关闭的批处理脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16510948/