S
S
Sergey Lehmann2020-08-19 18:58:15
Computer networks
Sergey Lehmann, 2020-08-19 18:58:15

How to make ping in cmd every 5 minutes?

Good evening.
there is a code

:repeat  
setlocal enabledelayedexpansion 
set ip=192.168.1.205
set t=2 
:# 
ping -4 -n 1 %ip%| find/i "TTL="&& goto # 
:## 
ping -4 -n 2 %ip%| find/i "TTL="&& (goto #& set n=)|| ( 
set/a n+=1& if !n! lss %t% (goto ##) else (C:\Program Files\Oracle\VirtualBox\VBoxManage.exe startvm Cloud --type headless) 
) 
TIMEOUT /T 600 /NOBREAK
goto :repeat
endlocal

It checks the ping to the local address, but if successful, it pings to the new one too quickly. How can I ping every 5 minutes? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey Lehmann, 2020-08-19
@SSK28

Added before ping -4 -n 1 %ip%| find/i "TTL="&& goto # string TIMEOUT /T 300 /NOBREAK.

X
xmoonlight, 2020-08-19
@xmoonlight

1. Download/create a console runtime delay utility.
2. Use the assigned task manager.
Here are all the ways.

S
Saboteur, 2020-08-19
@saboteur_kiev

Why ping?

@echo off
SETLOCAL EnableDelayedExpansion

:beginloop
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" list runningvms | FINDSTR Cloud
if %errorlevel% EQU 0 (
  echo Is running
) else (
  echo VM is not running, tryint to start:
  rem C:\Program Files\Oracle\VirtualBox\VBoxManage.exe startvm Cloud --type headless
)
timeout /T 60 /NOBREAK
goto :beginloop

Better yet, put the script on the schedule through the schedule service, and not turn the script in the window.

A
AUser0, 2020-08-19
@AUser0

However, the first ping should be:
ping -4 -n 1 %ip%| find/i "TTL=" && ( TIMEOUT /T 300 /NOBREAK ; goto # )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question