Do command when file 3rd-to-last line does NOT contain a string

DynV

New member
Mar 15, 2020
50
0
0
Visit site
I'm having connection issues which I'm documenting. I have a close variant of the following that has 60 seconds in between each call, but I'd like one to be continuous until the connection is reestablished. The way I see it, at the end of the following there would be some way of checking the log content and if what's at the end of the log reflect a disconnection and if so immediately make another call.

echo %time:~0,5%
@set yymmdd=%date:~12,2%%date:~7,2%%date:~4,2%
echo %date% >> logs\pinger-%yymmdd%.txt
::using "time /t | tee -a [...]" take 4 time the processing of doing the command twice
echo %time:~0,5% >> logs\pinger-%yymmdd%.txt
ping google.ca >> logs\pinger-%yymmdd%.txt
pinger-win10.bat
and since a good ping should end with something like
Ping statistics for 172.217.13.99:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 12ms, Maximum = 12ms, Average = 12ms
but when the ping goes bad it's like
Request timed out.

Ping statistics for 172.217.13.99:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
, I think the batch last line would be something like if
SEARCH logs\pinger-%yymmdd%.txt -line max-3 -match false "(0% loss)" then pinger-win10.bat REM else it stops
; that's just an example and I'm not good at these kind of things. If I managed to do this, with the amount of times it would be started and the average interruption duration, I doubt the log would be > 1000 lines but also < 200; and since my intention is to have a ping every 10-15 seconds, whatever solution to automatically stop the continuous ping need to be < 5-10 seconds.

TLDR How to do a command if a file 3rd-to-last line does NOT contain a specific string?

Thank you kindly for your assistance
 
Last edited by a moderator:

Members online

Forum statistics

Threads
323,196
Messages
2,243,431
Members
428,035
Latest member
jacobss