I’m posting a bash script I’ve made for my own purposes that checks when the devices specified were last seen connecting to the device where this script is being run from:
Feel free to adapt it to your needs, but please use at your own risk. You can also add it to your crontab to be run on a schedule, should you so desire.
NOTE: You need jq for the script to parse properly.
I did something like that on one of my Win11 Devices with Task Scheduler and a batch file. I don’t care to use PowerShell.
for /f “delims=” %%i in (‘curl -sk -H “X-API-Key: %MONAPIKEY%” https://%MONTAILIP%:8384/rest/stats/device ^| jq .““%MONDEVID%”.lastSeen”’) do set “SLSMON=%%i”
if “%SLSMON:~21,5%” == “05:00” SET TZ=CDT
if “%SLSMON:~21,5%” == “06:00” SET TZ=CST
SET LSMONDATE=%SLSAPH:~1,10%
SET LSMONTIME=%SLSAPH:~12,8%
SET CXNMON=DOWN - Last Seen %LSMONDATE% at %LSMONTIME% %TZ%
Sir, I went through it character by character. The quotes from this snippet are correct. The mixture of weird batch file limitations with jq make it look funky.
What I mean is that the forum has changed all vertical " and ' quotation marks to their curly alternatives “ and ”, and ‘ and ’, which I doubt will work in an actual batch script .