windows 下 shutdown.bat无法关闭tomcat

问题:使用脚本定时重启tomcat,调用了bin目录下的shutdown.bat,发现关不掉tomcat...

方案:通过tomcat端口号查找进程,杀死tomcat相关进程,启动tomcat

@echo off & setlocal EnableDelayedExpansion
 
title 重启tomcat
 
for %%a in (8080,8443,8009) do (
    set pid=0
    for /f "tokens=2,5" %%b in ('netstat -ano ^| findstr ":%%a"') do (
        set temp=%%b
        for /f "usebackq delims=: tokens=1,2" %%i in (`set temp`) do (
            if %%j==%%a (
                taskkill /f /pid %%c
                set pid=%%c
                echo 端口号【%%a】相关进程已杀死
            ) else (
                echo 不是本机占用端口【%%a】
            )
        )
    )
    if !pid!==0 (
       echo 端口号【%%a】没有占用
    )
)
 
echo tomcat相关进程已杀死
 
ping -n 10 127.0.0.1>nul
 
cd D:\Apache Software Foundation\bin
 
call startup.bat
 
echo tomcat已启动
 
echo 操作完成

 

posted @ 2024-05-31 17:48  锐洋智能  阅读(134)  评论(0编辑  收藏  举报