Batch file Psexec命令异常行为
我正在运行以下代码: master.bat:Batch file Psexec命令异常行为,batch-file,windows-server-2008,remote-access,psexec,Batch File,Windows Server 2008,Remote Access,Psexec,我正在运行以下代码: master.bat: @echo off call :Commands >D:\Test\log.txt exit /b :Commands @echo off setlocal for /F "delims= " %%i in (D:\Test\servers.txt) do ( psexec \\%%i -c D:\Test\script.bat ) exit server1 server2 server3 taskkill /F /IM notepad
@echo off
call :Commands >D:\Test\log.txt
exit /b
:Commands
@echo off
setlocal
for /F "delims= " %%i in (D:\Test\servers.txt) do ( psexec \\%%i -c D:\Test\script.bat )
exit
server1
server2
server3
taskkill /F /IM notepad.exe
taskkill /F /IM firefox.exe
taskkill /F /IM explorer.exe
C:\Windows\system32>taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 8932 has been terminated.
C:\Windows\system32>taskkill /F /IM firefox.exe
SUCCESS: The process "firefox.exe" with PID 7580 has been terminated.
C:\Windows\system32>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 8932 has been terminated.
C:\Windows\system32>taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 7586 has been terminated.
C:\Windows\system32>taskkill /F /IM firefox.exe
SUCCESS: The process "firefox.exe" with PID 8032 has been terminated.
C:\Windows\system32>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 7530 has been terminated.
在哪里
servers.txt:
@echo off
call :Commands >D:\Test\log.txt
exit /b
:Commands
@echo off
setlocal
for /F "delims= " %%i in (D:\Test\servers.txt) do ( psexec \\%%i -c D:\Test\script.bat )
exit
server1
server2
server3
taskkill /F /IM notepad.exe
taskkill /F /IM firefox.exe
taskkill /F /IM explorer.exe
C:\Windows\system32>taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 8932 has been terminated.
C:\Windows\system32>taskkill /F /IM firefox.exe
SUCCESS: The process "firefox.exe" with PID 7580 has been terminated.
C:\Windows\system32>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 8932 has been terminated.
C:\Windows\system32>taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 7586 has been terminated.
C:\Windows\system32>taskkill /F /IM firefox.exe
SUCCESS: The process "firefox.exe" with PID 8032 has been terminated.
C:\Windows\system32>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 7530 has been terminated.
script.bat:
@echo off
call :Commands >D:\Test\log.txt
exit /b
:Commands
@echo off
setlocal
for /F "delims= " %%i in (D:\Test\servers.txt) do ( psexec \\%%i -c D:\Test\script.bat )
exit
server1
server2
server3
taskkill /F /IM notepad.exe
taskkill /F /IM firefox.exe
taskkill /F /IM explorer.exe
C:\Windows\system32>taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 8932 has been terminated.
C:\Windows\system32>taskkill /F /IM firefox.exe
SUCCESS: The process "firefox.exe" with PID 7580 has been terminated.
C:\Windows\system32>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 8932 has been terminated.
C:\Windows\system32>taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 7586 has been terminated.
C:\Windows\system32>taskkill /F /IM firefox.exe
SUCCESS: The process "firefox.exe" with PID 8032 has been terminated.
C:\Windows\system32>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 7530 has been terminated.
我正在运行master.bat安装server2,一切正常,但我在这里面临的问题是:我验证了在本地server2上脚本也成功运行,但没有本地server2的日志出现在log.txt文件中,如下所示,而server1和server3的日志按预期出现:
log.txt:
@echo off
call :Commands >D:\Test\log.txt
exit /b
:Commands
@echo off
setlocal
for /F "delims= " %%i in (D:\Test\servers.txt) do ( psexec \\%%i -c D:\Test\script.bat )
exit
server1
server2
server3
taskkill /F /IM notepad.exe
taskkill /F /IM firefox.exe
taskkill /F /IM explorer.exe
C:\Windows\system32>taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 8932 has been terminated.
C:\Windows\system32>taskkill /F /IM firefox.exe
SUCCESS: The process "firefox.exe" with PID 7580 has been terminated.
C:\Windows\system32>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 8932 has been terminated.
C:\Windows\system32>taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 7586 has been terminated.
C:\Windows\system32>taskkill /F /IM firefox.exe
SUCCESS: The process "firefox.exe" with PID 8032 has been terminated.
C:\Windows\system32>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 7530 has been terminated.
PsExec命令为什么会出现这种异常行为
运行master.bat后编辑:server2上的cmd屏幕输出:
@echo off
call :Commands >D:\Test\log.txt
exit /b
:Commands
@echo off
setlocal
for /F "delims= " %%i in (D:\Test\servers.txt) do ( psexec \\%%i -c D:\Test\script.bat )
exit
server1
server2
server3
taskkill /F /IM notepad.exe
taskkill /F /IM firefox.exe
taskkill /F /IM explorer.exe
C:\Windows\system32>taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 8932 has been terminated.
C:\Windows\system32>taskkill /F /IM firefox.exe
SUCCESS: The process "firefox.exe" with PID 7580 has been terminated.
C:\Windows\system32>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 8932 has been terminated.
C:\Windows\system32>taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 7586 has been terminated.
C:\Windows\system32>taskkill /F /IM firefox.exe
SUCCESS: The process "firefox.exe" with PID 8032 has been terminated.
C:\Windows\system32>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 7530 has been terminated.
我再次勾选,脚本成功地在server2上运行,并且在cmd屏幕上也可以看到它,但server2的日志中仍然并没有显示它。我也使用-accepteula选项进行了测试,但行为没有变化。我将我的cmd屏幕输出放在这里:
PsExec v2.0 - Execute processes remotely
Copyright (C) 2001-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
Starting D:\Test\script.bat on server1...
script.bat existed on server1 with error code 0.
PsExec v2.0 - Execute processes remotely
Copyright (C) 2001-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
D:\Test\script.bat existed with error code 0.
PsExec v2.0 - Execute processes remotely
Copyright (C) 2001-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
Starting D:\Test\script.bat on server3...
script.bat existed on server3 with error code 0.
您是否检查了server2上的事件日志以确认它是否尝试执行远程psexec或从您执行批处理脚本的位置执行psexec。您是否在server2上至少运行过一次psexec?如果没有,您必须运行它并接受eula。或者,您也可以将/accepteula开关添加到PsExec调用中。@Matt..我再次勾选了,脚本成功地在server2上运行,并且在cmd屏幕上也可以看到它,但server2的日志中仍然没有显示它。我也使用-accepteula选项进行了测试,但行为没有改变。我已将我的cmd屏幕输出放在上面的编辑中。@Chelsea..是..我检查了server2上的事件日志,script.bat在server2上成功运行,上述编辑中提到的server2上的cmd屏幕输出也清楚显示了这一点。