gpt4 book ai didi

powershell - 使用CMD或POWERSHELL查找失败的日志文件

转载 作者:行者123 更新时间:2023-12-03 00:42:08 25 4
gpt4 key购买 nike

我有数百个日志文件import.log,成功的日志文件的最后一行是“Task finished successfully”。

每个日志文件都位于单独的目录中,因此我的搜索任务是遍历目录。读取每个import.log并报告的完整路径,但失败 import.log

失败的import.log是否而不是不包含“Task finished successfully”。
或者,import.log的最后一行不是“Task finished successfully

我目前的解决方案中,我只找到成功的import.log

findstr /s /m "Task finished successfully" import.log

请建议如何使用CMD工具首选查找失败的日志文件,第二选择是POWERSHELL解决方案。

最佳答案

我知道这是您的第二选择,但这是您要查找的内容的摘要。

$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"

关于powershell - 使用CMD或POWERSHELL查找失败的日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59080362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com