测试远程单元上的进程是否为 运行 并输出到日志

Test if process is running on remote units and output to log

我们想检查某个进程是否在我们列出的任何服务器上 运行,将结果输出到日志文件,如下所示:

SERVERNAME Process is running
SERVERNAME Process is not running

我是批处理的新手,但这是我的进展:

FOR /F "TOKENS=*" %%A IN (LIST.TXT) DO TASKLIST /S %%A /FI "IMAGENAME EQ IEXPLORE.EXE" >> ECHO %%A D:\SEARCH.LOG  

你所拥有的,离获得你要求的输出不远了,但是,你可以像这样改变你的脚本:

@ECHO OFF
(FOR /F "TOKENS=*" %%A IN (LIST.TXT
    ) DO TASKLIST /S %%A|FIND /I "IEXPLORE.EXE">NUL&&(Echo %%A Process is running
    )||Echo %%A Process is not running)>D:\SEARCH.LOG

这应该可以满足您的需求。

  @echo off
   setlocal enabledelayedexpansion
   for /F "delims=" %%a in (list.txt) do (
     tasklist /s %%a | find /I "iexplore.exe" >nul
      if !errorlevel! equ 0 (echo %%a Process is Running) else (echo %%a Process is Not Running)
 ) >> d:\search.log

至于你对 RPC 错误的要求,也许可以考虑 rpcping 如果不可用则回显到文件。

@echo off
setlocal enabledelayedexpansion
for /F "delims=" %%a in (list.txt) do (
    rpcping -s %%a |find /i "Completed" >nul
    if not !errorlevel! equ 0 echo %%a RPC Server not available
    tasklist /s %%a | find /I "iexplore.exe" >nul
    if !errorlevel! equ 0 (echo %%a Process is Running) else (echo %%a Process is Not Running)
 ) >> d:\search.log