我知道这是您的第二选择,但这是您要查找的内容的摘要。
$folder = "C:\folder\test\*"
$files = gci -Path $folder -Force -recurse -File -include "*.log"
foreach ($file in $files){
$content = gc $file.FullName -raw | Out-Null
if($content -match "Task finished successfully"){
Write-host $File.Name imported successfully
# Do more stuff.
}
elseif((Get-Item $file.FullName).length -eq 0){
Write-host $file is empty.
#Do more stuff
}
else{
Write-host $file import was unsuccessful.
#Do more stuff
}
}
您可以将Powershell脚本命名为“ checklogs.ps1”,然后使用以下命令从.bat调用它:
@echo off
powershell.exe -executionpolicy bypass -file "C:\folder\checklogs.ps1"
,
以下来自avery_larry的有用评论。我创建了一个笨拙的解决方案。
我写了一个批处理文件find-failed-imports.bat
find-failed-imports.bat
echo off
for /r .. %%a in (import.l?g) do (findstr "Task finished successfully" "%%a" >nul || echo %%a failed)
欢迎任何更好的解决方案。
,
请尝试在某些任务未成功的地方使用日志文件。
在文件上获取结果时(也在Crtl + c中)。
我建议这样:
@echo off
set "_err=.\log_error.log" && set "_str=Task.finished.successfully"
for /r . %%a in (import.log)do findstr "%_str%" "%%~a" >nul || echo=%%~a>>"%_err%"
if exist "%_err%" type "%_err%"|clip & type "%_err%"
exit /b
不好:
为成功阻止 un ,请使用: "Task.finished.successfully"
使用 regex [.]
== wildcard: any character
了解更多关于 FindSTR
in this link
- 更新:建议检查名称== imp * error.log且文件大小> 0的文件的大小
@echo off && cd /d "%~dp0"
set "err=.\log_error.log" && set "str=Task finished successfully"
for /f tokens^=* %%a in ('dir /s /b imp*.log')do if %%~Za neq 0 (
echo %%~nxa|find /i ".error.log" >nul && echo="%%~fa" >>"%err%"
) || ( find /i /v "%str%" "%%~a" >nul && echo="%%~fa" >>"%err%")
(if exist "%err%" type "%err%" | clip && type "%err%") && exit /b
对不起,我的英语
本文链接:https://www.f2er.com/3017671.html