Or a remote file STATUS.txt whose content is an OPEN or CLOSE word.
The aim is to copy the status followed by a timestamp to a local file. And to send a Pushover alert if the new status is different from the previous one.
The local file is created on first reading under the name date_time-log.txt
The local file 2024-04-29_2223-log.txt should look like this :
1 2024-04-29_2223
2 CLOSE 2223
3 CLOSE 2224
4 OPEN 2225
5 OPEN 2226
6 OPEN 2227
7 CLOSE 2228
8 CLOSE 2229
9 CLOSE 2230
with an “OPEN” alert at 2225 and a “CLOSE” alert at 2228
The Pushover alert is commited with
curl -s –form-string “token=%APP_TOKEN%” –form-string “user=%USER_KEY%” –form-string “message=Status : OPEN” https://api.pushover.net/1/messages.json > nul
and I already have %APP_TOKEN% and %USER_KEY%
Here is for distant reading :
@echo off
set "url=http://status.abc.com/S1R3.txt"
set "destination=C:StatusS1R3.txt"
For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%b-%%a)
For /f "tokens=1-2 delims=/: " %%a in ("%TIME%") do (if %%a LSS 10 (set mytime=0%%a%%b) else (set mytime=%%a%%b))
set datetime=%mydate%_%mytime%
echo %datetime% > %datetime%-log.txt
:loop
bitsadmin /transfer "CopieFichier" /priority normal "%url%" "%destination%"
type C:StatusS1R3.txt >> %datetime%-log.txt
For /f "tokens=1-2 delims=/: " %%a in ("%TIME%") do (if %%a LSS 10 (set mytime=0%%a%%b) else (set mytime=%%a%%b))
echo %mytime% >> %datetime%-log.txt
timeout /t 60 >nul
goto loop
But status changes detection is a problem…
smbd91 smbd91 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.