K
K
Kotyamba2010-12-15 10:59:19
cmd/bat
Kotyamba, 2010-12-15 10:59:19

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

7 answer(s)
B
bagyr, 2010-12-15
@bagyr

$lastline = gcxxx.log | select -last 1
if ($lastline -eq "Everything is Ok") {write-host Wheee!}
PowerShell

M
mambet, 2010-12-17
@mambet

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!

True, it will only work under some Windows not younger than XP.

K
Kalantyr, 2010-12-15
@Kalantyr

Maybe it's better to do it with PowerShell?

4
4eS, 2010-12-15
@4eS

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.

S
Sergey, 2010-12-15
@bondbig

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

S
Sergey, 2010-12-15
@bondbig

findstr "Everything is Ok" c:\path\to\logfile.log

S
SegaZero, 2010-12-15
@SegaZero


@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

something like this. grep has sparks, the cut utility can be taken from cygwin for example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question