check socket connection and reboot: socketNreboot.bat
Thursday, October 7, 2010 4:27:57 PM
@echo off
:: check if the socket can be established
SET SOCKETORNOT=
for /f "tokens=1 usebackq" %%A in (`perl checksocket.pl`) do (SET SOCKETORNOT=%%A)
if "%SOCKETORNOT%" == "NOTCONNECTED" goto REBOOTNOW
echo Network is alive...
:: start checking whether the connection is alive in netstat!!
SET WMSPORT=8080
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
goto EXIT
:REBOOTNOW
:: print out reboot time to error log and restart Windows...
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% Windows reboots...>> checkwmserr.txt
shutdown -r
goto EXIT
:EXIT
echo exiting...
:: check if the socket can be established
SET SOCKETORNOT=
for /f "tokens=1 usebackq" %%A in (`perl checksocket.pl`) do (SET SOCKETORNOT=%%A)
if "%SOCKETORNOT%" == "NOTCONNECTED" goto REBOOTNOW
echo Network is alive...
:: start checking whether the connection is alive in netstat!!
SET WMSPORT=8080
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
goto EXIT
:REBOOTNOW
:: print out reboot time to error log and restart Windows...
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% Windows reboots...>> checkwmserr.txt
shutdown -r
goto EXIT
:EXIT
echo exiting...






