0

每天我都通过手动 ( start -> run ->services.msc) 检查 Windows 服务。

但我想通过脚本自动化它。

如何使用 UNIX 脚本(.bat)检查特定窗口服务(例如 .tomcat)的状态(启动或停止)?

4

1 回答 1

0

您可以使用sc querynet start来执行此操作。

例如。

@echo off
sc query "ServiceName" | findstr RUNNING
if %ERRORLEVEL% == 0 goto working
echo Not Running
:working
echo Running
goto end
:end

或者

@echo off
net start | findstr "ServiceName"
if %ERRORLEVEL% == 0 goto working
echo Not Running
goto end
:working
echo Running
:end
于 2013-05-24T06:35:59.287 回答