Reputation: 6793
Windows Batch File:
I have a log that is created by a process. Now I want to create a batch file that checks this log file for a specific success message:
BDX 2013/07/25 23:08:02 -I- DATABASE SUCCESSFULL
Now there are several of these success entries at different timestamps in the log file, since the log file just adds the latest success messages.
So I want to check the log file for the LATEST success message, and compare it to the date stamp on the log file (date value of the log file, meaning the last time it was written to): If the date of the latest success entry in the log file matches the log file's date stamp, it should run another batch file (eg. call another.bat). If it does not match, meaning the last success entry is older than the timestamp on the log file, it should just write an error log (error.log) containing the words: 'DATABASE UNSUCCESSFUL' with the current timestamp next to it...
Is this possible?
Thanks
Upvotes: 0
Views: 1302
Reputation: 37569
try this:
for /f "tokens=2" %%a in ('findstr /i /c:"DATABASE SUCCESSFULL" logfile.txt') do set "success=%%a"
for %%a in (logfile.txt) do set "filedate=%%~ta"
if "%filedate:~0,10%"=="%success%" (
call another.bat
) else (
>>otherlogfile.log echo(%date% %time% DATABASE UNSUCCESSFUL
)
Upvotes: 3