BAT批处理判断服务是否正常运行的方法(批处理命令综合应用)(bat批处理命令运行程序)真没想到

随心笔谈1年前 (2023)发布 admin
129 0


@echo off
color 2E
set YYYYmmdd=%date:~0,4%%date:~5,2%%date:~8,2%
set hhmiss=%time:~0,2%%time:~3,2%%time:~6,2%
set filename=healthcheck.log
REM set “filename=healthcheck_%YYYYmmdd%_%hhmiss%.log”
set “datetime=%YYYYmmdd%%hhmiss%”
set allCount=0
set errorCount=0
set checkList=”QlikSenseServiceDispatcher” “QlikSenseSchedulerService” “QlikSenseRepositoryService” “QlikSenseRepositoryDatabase” “QlikSenseProxyService” “QlikSensePrintingService” “QlikSenseEngineService” “QlikLoggingService”
echo============================================>%filename%
echo Health Checking by Qlik Team >>%filename%
echo zhengkai.blog.csdn.net
echo (datetime: %datetime% ) >>%filename%
echo============================================>>%filename%
echo. >>%filename%
echo. >>%filename%
for %%L in (%checkList%) do call :health_check %%L
echo============================================>>%filename%
echo Checking Finish. >>%filename%
echo. >>%filename%
echo Error : %errorCount% of %allCount% >>%filename%
echo. >>%filename%
echo============================================>>%filename%
call :check_status
echo============================================>>%filename%
goto:end

:health_check
sc query |find /i %1 >nul 2>nul
if not errorlevel 1 (
echo SUCCESS…… %1 >>%filename%
)else (
echo FAILD…… %1 is error ! >>%filename%
set /a errorCount+=1
)
set /a allCount+=1
goto:eof

:check_status
if %errorCount% gtr 0 (
echo ###### this server is Not Health >>%filename%
) else (
echo ###### this server is Health >>%filename%
)
goto:eof

:end
copy %filename% \\xxxx\DataShare\CSDN\ZhengKai\

© 版权声明

相关文章