我们想检查某个进程是否在我们列出的任何服务器上运行,并将结果输出到这样的日志文件中:
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
答案 0 :(得分:0)
你有什么,不是很远,为了得到你要求的输出,你可以更改你的脚本:
@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
答案 1 :(得分:0)
这应该可以做你想要的。
@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