Is this possible to be done?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Robertlio22
Posts: 1
Joined: 12 Mar 2019 04:29

Is this possible to be done?

#1 Post by Robertlio22 » 14 Mar 2019 07:13

Hi,

I would like to Ping the site [LINK REMOVED] every 10 minutes and update a text file with the word "Live" in case of reply and "Down" in case of no reply with date and time.

If it's possible can someone guide me?
Last edited by aGerman on 14 Mar 2019 07:17, edited 1 time in total.
Reason: hyperlink removed

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Is this possible to be done?

#2 Post by aGerman » 14 Mar 2019 09:17

Code: Select all

@echo off &setlocal

set "logfile=pingstat.txt"

for /l %%i in () do (
  >nul ping nonsense.com

  if errorlevel 1 (
    >"%logfile%" echo Down
  ) else (
    >"%logfile%" echo Live
  )

  >nul timeout /t 600 /nobreak
)
Use >>"%logfile%" if "update" means "append" rather than "overwrite".

Steffen

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Is this possible to be done?

#3 Post by Aacini » 14 Mar 2019 09:34

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set "reply[0]=Down" & set "reply[1]=Live"

(for /L %%i in () do (
   ping nonsense.com >nul
   call echo %%reply[!errorlevel!]%%
) > logfile.txt
Antonio

Post Reply