我需要一个脚本来检查单个服务器中多个服务的状态,并且服务的状态应以合并格式显示在单个文本文件中,并且还需要在指定的时间内向相关人员发送邮件。
谁能帮我这个?
答案1
这是我使用的脚本。
Echo Off
Setlocal EnableDelayedExpansion
IF EXIST Result.csv DEL Result.csv
FOR /F "Tokens=*" %%L IN (Servers.txt) DO (
SET ServerName=
SET ServerName=%%L
SC.exe \\!ServerName! Query MapGenServer > Result.txt
SC.exe \\!ServerName! Query MECServer > Result1.txt
)
Find /i "RUNNING" < Result.txt
IF !ErrorLevel! == 0 (
Echo !ServerName!, Running >> Result.txt
) ELSE (
Echo !ServerName!, Not Running >> Result.txt
Find /i "RUNNING" < Result1.txt
IF !ErrorLevel! == 0 (
Echo !ServerName!, Running >> Result1.txt
) ELSE (
Echo !ServerName!, Not Running >> Result1.txt
)