Answer the question
In order to leave comments, you need to log in
Creating *.bat file?
Tell me how to make a check in the file:
There is a xxx.log file larger than 10 MB. at the very end there should be a line “Everything is Ok”, how to check this line, if it exists, then execute the command such and such, if not, then exit the script.
OS: Windows
Answer the question
In order to leave comments, you need to log in
$lastline = gcxxx.log | select -last 1
if ($lastline -eq "Everything is Ok") {write-host Wheee!}
PowerShell
I can't resist :) GREPs, PowerShells are unsportsmanlike.
Slow version using pure batch:
for /f "delims=" %%a in (build.xml) do set lastLine="%%a"
if %lastLine%=="Everything is Ok" echo YEAH!
I think the %ERRORLEVEL% variable will help you.
If the desired combination is found in the file, the variable will return "0", otherwise "1".
For example:
find "Everything is Ok" <D:\filename.log
if %ERRORLEVEL%==1 start start.cmd
if %ERRORLEVEL%==1 pause
If the line is found, start.cmd will be executed if there is no such line in the file, the script will wait for any key to be pressed.
Slash in the path to the file beguiled)
@echo off
findstr "Everything is Ok" d:/test.txt >null
if errorlevel 1 GOTO EXIT
:COMMAND
echo
echo "Whoooohoo!"
:EXIT
exit 0
@echo off
for /F %%I in ('"find /n /i "everything is ok" file.txt | cut -f 1 -d ] | cut -f 2 -d ["') do SET Number=%%I 2>nul
For /F "Tokens=3" %%A In ('Find /V /C "" file.txt') Do Set sCount=%%A
If %sCount% GEQ %Number% Echo whoohoo
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question