I have a .log file that is constantly being added new lines and I want to have a batch script that detects when the new line has a specific string.
First, I copy the .log file and change it into a .txt Then I read the last line
Here is an example of what a line in the .txt that should be detected is:
[05:35:26] [Client thread/INFO]: [CHAT] §6§lP§e§lrof
Here is the code I'm using:
:search
del C:\Users\Diogo\Desktop\Detector\latest.txt
del C:\Users\Diogo\Desktop\Detector\latest.log
xcopy /s "C:\LocationofFile\latest.log" "C:\Users\Diogo\Desktop\Detector"
RENAME "C:\Users\Diogo\Desktop\Detector\latest.log" "latest.txt"
@echo off & setlocal enabledelayedexpansion
for /f "tokens=*" %%c in (C:\Users\Diogo\Desktop\Detector\latest.txt) do (
set temp=%%c
)
echo !temp!
(echo !temp! | findstr /i /c:"§6§lP§e§lrof" >nul) && (GOTO found) || (echo Variable does not have the string "§6§lP§e§lrof")
Endlocal
GOTO search
:found
pause
For some reason it doesn't detect it.
Any ideas?
Thank you in advance :D
EDIT: tried Powershell, here is the code right now (yes, I am searching the line for 2 different things):
while ($True) {
Write-Output 'Enter <ctrl><c> to break out of this loop.'
Start-Sleep -Seconds 1
Copy-Item -LiteralPath "C:\LocationOfFile\latest.log" -Destination "C:\Users\Diogo\Desktop\Detector"
Rename-Item -Path "C:\Users\Diogo\Desktop\Detector\latest.log" -NewName "latest.txt"
Get-Content -Path "latest.txt" -tail 1 -wait | Select-String -Quiet '§6§lP§e§lrof'
if (System.Boolean -eq True) {
Invoke-Item result1.bat
pause
}
else {
Get-Content -Path "latest.txt" -tail 1 -wait | Select-String -Quiet 'spawned'
if (System.Boolean -eq True) {
Invoke-Item result2.bat
pause
}
else {
Nope
pause
}
}
}