下面的脚本可以工作,但是当它击中离线主机时会减慢的。
@echo off
rem Setup the output file. This just wipes the pre-existing file from last set of data mining
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
for /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
echo %mydate%_%mytime% > output\datamine.txt
**setlocal enabledelayedexpansion
for /f %%a in (hosts.txt) do (
psexec \\\%%a findstr /I ":" "C:\ProgramData\Firewall\event.log" >> output\datamine.txt )
endlocal**我用ping语句重写,打算跳过不应答的主机。这是它的肉:
for /f %%a in (hosts.txt) do (<br>
ping -n 1 -w 100 %%a | for /f "skip=1 tokens=3 delims= " %%b in ('findstr bytes') do (set COMPNAME=%%b)
if errorlevel 1 goto FAIL
psexec \\%%a findstr /I ":" "C:\ProgramData\Firewall\event.log" >> output\datamine.txt )
goto END
:FAIL
echo host not answering
:END
endlocal这个问题很明显,因为当主机无法回答ping时,我就退出do循环。我需要脚本来查看错误级别1,然后跳到下一个主机。不知道该在哪里结束循环。此外,我也不太确定我选择的“后藤”行。有什么建议吗?
发布于 2013-11-01 18:11:15
你要退出你的for循环了。而不是执行goto添加一个after并在其后面移动括号。
下面是我编写的一个函数,用于完成这个任务,以及如何实现它。
for /f %%a in (hosts.txt) do (
call :IsPingable %%a && (
psexec \\%%a findstr /I ":" "C:\ProgramData\Firewall\event.log" >> output\datamine.txt
) || (
echo host %%a not answering
)
)
exit /b
:IsPingable comp
ping -n 1 -w 3000 -4 -l 8 "%~1" | Find "TTL=">nul
exit /b发布于 2013-11-01 18:42:03
示例代码:
for /f %%a in (hosts.txt) do ping -n 1 "%%a">nul && call :success "%%a"|| call :fail "%%a"
goto:eof
:success
echo success: %~1
goto:eof
:fail
echo fail: %~1
goto:eofhttps://stackoverflow.com/questions/19732502
复制相似问题