netstat check and restart service with perl: checkwms.bat
Thursday, October 7, 2010 4:31:31 PM
@echo off
:: start checking whether the connection is alive in netstat!!
SET WMSPORT=1030
netstat | find "localhost:%WMSPORT%" > checkwms.log
SET WMSON=
for /f "tokens=4" %%A in (checkwms.log) do (SET WMSON=%%A)
if not "%WMSON%" == "ESTABLISHED" goto DOWN
echo WMS keeps running...
goto EXIT
:DOWN
:: print out down time to error log and restart WMServer...
for /f "tokens=1-2 usebackq" %%A in (`date /T`) do (SET NOWDATE=%%A %%B)
for /f "tokens=1-2 usebackq" %%A in (`time /T`) do (SET NOWTIME=%%A %%B)
echo %NOWDATE% %NOWTIME% WMS connection restarts...>> checkwmserr.txt
sc stop WMServer
sc start WMServer
:EXIT
echo exiting...
:: start checking whether the connection is alive in netstat!!
SET WMSPORT=1030
netstat | find "localhost:%WMSPORT%" > checkwms.log
SET WMSON=
for /f "tokens=4" %%A in (checkwms.log) do (SET WMSON=%%A)
if not "%WMSON%" == "ESTABLISHED" goto DOWN
echo WMS keeps running...
goto EXIT
:DOWN
:: print out down time to error log and restart WMServer...
for /f "tokens=1-2 usebackq" %%A in (`date /T`) do (SET NOWDATE=%%A %%B)
for /f "tokens=1-2 usebackq" %%A in (`time /T`) do (SET NOWTIME=%%A %%B)
echo %NOWDATE% %NOWTIME% WMS connection restarts...>> checkwmserr.txt
sc stop WMServer
sc start WMServer
:EXIT
echo exiting...






