Windows server利用批处理脚本判断端口, 启动tomcat
Windows server服务器上面的tomcat老是不定时挂掉, 于是利用定时操作脚本判断tomcat80端口是否在运行, 如果运行则放过, 如果down掉就启动tomcat,解决tomcat不定时挂掉导致业务数据流通丢失问题
- @echo off<nul 3>nul
- @echo off&title Checking For System, Do Not Switch Off, Thankyou...
- set num=8090
- for /f "tokens=3 delims=: " %%a in ('netstat -an') do (
- if "%%a"=="%num%" goto en
- )
- if not "%%a"=="%num%" goto en1
-
- :en
- echo.Checking For local%NUM%Port is Opening...
- pause
- exit
-
- :en1
- echo.Checking For local%NUM%Port is Not Opening...
- echo.Starting Tomcat Program...
- call "%CATALINA_HOME%"\bin\startup.bat
- echo.Starting Succes!
- echo.OK!
-
- pause
- exit
第一段代码@echo off<nul 3>nul
::如果放在win启动计划中,如需要就开启第六行代码,
::作用是检测完马上自动关闭检测脚本待下次运行, 如果不开启就是检测完停留等待手动关闭,
::作用:窗口叠加