windows版本的定时任务

 需求:

tomcat存在异常问题,有时tomcat上的war包自动就断开了,然后写了一个windows脚本,作用是定时检查,每隔50s检查一次9999端口是否还在,要是不在立马执行启动tomcat的脚本

【注意】如果发现tomcat断了,我先执行shutdown.bat然后再给他留10s然后才执行启动tomcat的脚本。

@echo off
set CATALINA_HOME=E:\apache-tomcat-8.0.833-windows-x64\apache-tomcat
set ip=127.0.0.1
set "PORT_TO_CHECK=9999"

:monitor

netstat -ano | findstr ":%PORT_TO_CHECK%" > nul
if %errorlevel% == 0 (
    echo Tomcat is running.
) else (
    echo Tomcat is not running. Restarting...
	call %CATALINA_HOME%\bin\shutdown.bat
	timeout /t 10 /nobreak > NUL
    start %CATALINA_HOME%\bin\startup.bat
)

timeout /t 50 /nobreak > NUL
goto monitor

你可能感兴趣的:(windows,windows版本的定时任务,tomcat启动war包,java)