Search code examples
powershellcmdfindstr

Using CMD or POWERSHELL to find failed log files


I have hundreds of log files import.log, a successful log file has the last line "Task finished successfully".

Each log file is in a separate directory, so my search task is traversing the directories. Reading each import.log, and reporting the full path of a failed import.log.

A failed import.log does not contain "Task finished successfully". Or , the last line of import.log is not "Task finished successfully"

My current solution I find only the successful import.log

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

Please advise how to find the failed log files with CMD tools first choice, POWERSHELL solution is second choice.


Solution

  • Following useful comment from avery_larry . I created a clunky solution that works.

    I wrote a batch file 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)
    

    Any better solutions welcome.