1. 程式人生 > >批處理TOMCAT8.0自動重啟任務

批處理TOMCAT8.0自動重啟任務

@echo
title tomcat重啟

 

set num=7001  //埠號,根據tomcat的設定項設定
set JAVA_HOME=D:\software\Java\jdk1.8.0_131 //jkd位置

set CATALINA_HOME="D:/software/Apache Software Foundation/Tomcat 8.0" //tomcat位置(注:資料夾的空格問題,該檔案中不做新增,將其新增到環境變數中)

echo 刪除tomcat日誌檔案

//刪除檔案方式1(刪除定時天數中的檔案)

forfiles /p "D:\software\ Apache Software Foundation\Tomcat 8.0\logs" /s /m *.log /d -5 /c "cmd /c del @path
forfiles /p "D:\software\ Apache Software Foundation\Tomcat 8.0\logs" /s /m *.txt /d -5 /c "cmd /c del @path

forfiles /p "D:\software\ Apache Software Foundation\Tomcat 8.0\work" /s /m *.log /d -5 /c "cmd /c del @path
forfiles /p "D:\software\ Apache Software Foundation\Tomcat 8.0\work" /s /m *.txt /d -5 /c "cmd /c del @path

//刪除檔案方式2
del /f /s /q "D:/software/Apache Software Foundation/Tomcat 8.0/logs/*.*"
del /f /s /q "D:/software/Apache Software Foundation/Tomcat 8.0/work/*.*"

//刪除資料夾
rmdir /s /q "D:/software/Apache Software Foundation/Tomcat 8.0/work/work1"
rmdir /s /q "D:/software/Apache Software Foundation/Tomcat 8.0/work/Catalina"
echo 刪除tomcat日誌檔案完成!

 

//根據埠號進行判斷

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...

echo 1.End The JAva program!
call "D:/software/Apache Software Foundation/Tomcat 8.0/bin/shutdown.bat"

echo 2.Kill The Process!
taskkill /f /im java.exe /t

echo 3.MAke The Service To Be Running After Ten Seconds!
ping -n 10 localhost > nul

echo 4.MAke The Service To Be Running!
call "D:/software/Apache Software Foundation/Tomcat 8.0/bin/startup.bat"
echo Over!


:en1
echo.Checking For local%NUM%Port is Not Opening...
echo.Starting Tomcat Program...

echo 1.MAke The Service To Be Running!
call "D:/software/Apache Software Foundation/Tomcat 8.0/bin/startup.bat”

echo.Starting Succes!
echo.OK!