I guess it's better to create a post with all these scripts, but ok:
TelegramElectricityNotification script - runs by scheduler every 4 hours (during blackout period every 1 hour, I am from Ukraine). I use it to monitor if there's electricity in my house (usually we have blackout schedule, so with that script I can see patterns of how long and when my house gets electricity, when there is no message on schedule - I can plan my day more easily, so I won't hurry to get back home when it is no power in my area, etc..
/system script run FuncDeviceStatus
:global FuncStatus
:global textSent "$[$FuncStatus]%0A\E2\9C\85 <b>Power is still here</b>"
/system script run SendToTelegram
I use Netwatch script, to check if another Mikrotik (not connected to UPS) in my house is alive. By that i can monitor when electricity turns on/off, and disable/enable low-power mode and auxiliary wifi hotspot.
UP:
/system script run FuncDeviceStatus
:global FuncStatus
:global textSent "$[$FuncStatus]%0A\E2\9A\A1\F0\9F\94\8B <b>Electricity is back on. UPS is working</b>"
:log warning "[ELECTRICITY] Blackout-hotspot disabled. Exiting power saving mode"
/interface wireless cap set enabled=no
/system routerboard settings set cpu-frequency=auto
/system script run SendToTelegram
DOWN:
/system script run FuncDeviceStatus
:global FuncStatus
:global textSent "$[$FuncStatus]%0A\E2\9D\8C\F0\9F\94\8B <b>Electricity is down. UPS is working</b>"
:log warning "[ELECTRICITY] Blackout-hotspot enabled. Entering power saving mode"
/interface wireless cap set enabled=yes
/system routerboard settings set cpu-frequency=448MHz
/system script run SendToTelegram
SendToTelegram is used to send messages every script generates to my and my wife's Telegram:
I’m still using the script version that extracts the date from change log, not the URL. Seem to be still working just fine. At the moment. But MT could change that too.
Or at least document/publish the change in URLs. The, now wrong, “LATEST.7rc” URLs comes from older @normis forum post. So whatever automation you used to fetch the “latest long-term” would have broken.
e.g. any tool needs a HTTPS call to get the latest version of RouterOS from somewhere & they changed the URL that did that.
I still use the date stamp right in the release notes that are accessed by the update command.
Works perfectly.
#This script looks to see if there is a RouterOS update available, if so, it takes the date stamp from the release notes and calculates the nuber of
#days since the release. Then will update the local system if the time has been "DaysToWait".
#I run this script daily at 2AM
#G. Racino 01Oct2023
#Updated 12Oct2023 to directly access release date from MT web site release log. WIth help from @rextended and @diamuxin from MT forum
#days to wait after a new release before updating this device.
:local DaysToWait 30
:local DSR
/system package update set channel=stable
/system package update
check-for-updates once
:delay 5s;
:global LatestVer [/system package update get latest-version]
:global InstVer [/system package update get installed-version]
:log info "~~~~~~~~~~RouterOS update check: Latest Ver=$LatestVer, Installed Ver=$InstVer ~~~~~~~~~~~"
#The two below functions are used to convert the time stamps to a format that can be use in a simple subtract formula.
#They are from @rextended on MT forum
#http://forum.mikrotik.com/t/i-did-it-script-to-compute-unix-time/68576/28
:global datetime2epoch do={
:local dtime [:tostr $1]
/system clock
:local cyear [get date] ; :if ($cyear ~ "....-..-..") do={:set cyear [:pick $cyear 0 4]} else={:set cyear [:pick $cyear 7 11]}
:if (([:len $dtime] = 10) or ([:len $dtime] = 11)) do={:set dtime "$dtime 00:00:00"}
:if ([:len $dtime] = 15) do={:set dtime "$[:pick $dtime 0 6]/$cyear $[:pick $dtime 7 15]"}
:if ([:len $dtime] = 14) do={:set dtime "$cyear-$[:pick $dtime 0 5] $[:pick $dtime 6 14]"}
:if ([:len $dtime] = 8) do={:set dtime "$[get date] $dtime"}
:if ([:tostr $1] = "") do={:set dtime ("$[get date] $[get time]")}
:local vdate [:pick $dtime 0 [:find $dtime " " -1]]
:local vtime [:pick $dtime ([:find $dtime " " -1] + 1) [:len $dtime]]
:local vgmt [get gmt-offset]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)}
:if ($vgmt < 0) do={:set vgmt ($vgmt * -1)}
:local arrm [:toarray "0,0,31,59,90,120,151,181,212,243,273,304,334"]
:local vdoff [:toarray "0,4,5,7,8,10"]
:local MM [:pick $vdate ($vdoff->2) ($vdoff->3)]
:local M [:tonum $MM]
:if ($vdate ~ ".../../....") do={
:set vdoff [:toarray "7,11,1,3,4,6"]
:set M ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $vdate ($vdoff->2) ($vdoff->3)] -1] / 2)
:if ($M>12) do={:set M ($M - 12)}
}
:local yyyy [:pick $vdate ($vdoff->0) ($vdoff->1)] ; :if ((($yyyy - 1968) % 4) = 0) do={:set ($arrm->1) -1; :set ($arrm->2) 30}
:local totd ((($yyyy - 1970) * 365) + (($yyyy - 1968) / 4) + ($arrm->$M) + ([:pick $vdate ($vdoff->4) ($vdoff->5)] - 1))
:return (((((($totd * 24) + [:pick $vtime 0 2]) * 60) + [:pick $vtime 3 5]) * 60) + [:pick $vtime 6 8] - $vgmt)
}
#located http://forum.mikrotik.com/t/script-to-update-routeros-after-x-days-of-release/170000/18
:global date2ymd do={
:local dtime [:tostr $1]
:local yyyy; :local MM; :local dd; :local HH
# Date format: 2023-Aug-31 16:55
:if ([:len $dtime] = 17) do={
:set yyyy [:pick $dtime 0 4]; :set dd [:pick $dtime 9 11]; :set HH [:pick $dtime 12 17]
:set MM ([:find "xxanebarprayunulugepctovec" [:pick $dtime 6 8] -1]/2); :if ($MM < 10) do={:set MM "0$MM"}
}
:return "$yyyy-$MM-$dd $HH"
}
#Check release date of new version to see if it is DaysToWait days old before installing
:if ([/system package update get status] = "New version is available") do={
# Get the Changelog of the latest version of the package and save it in a text file.
:local VerChangeLog ([/tool fetch "http://upgrade.mikrotik.com/routeros/$LatestVer/CHANGELOG" output=user as-value] -> "data")
:local dateEx [:pick $VerChangeLog ([:find $VerChangeLog "("]+1) ([:find $VerChangeLog "):"]) ]
:local currDate [/system clock get date]
#:log info "dateEx=$dateEx currDate=$currDate"
:local EPOCHdateEx [$datetime2epoch [$date2ymd $dateEx]]
:local EPOCHcurrDate [$datetime2epoch $currDate]
:set DSR (([:tonum $EPOCHcurrDate]-[:tonum $EPOCHdateEx])/86400)
:if ($DSR <= $DaysToWait) do={
:log info "~~~~~~~~~New RouterOS release is out for $DSR days so NOT updating this device until release has been out for more than $DaysToWait days~~~~~~~~~~~~~~~~"
} else={
:log info "~~~~~~~~~~New RouterOS release is out for $DSR days so updating this device~~~~~~~~~";
:delay 3s;
/system package update install
}
} else={
:log info "~~~~~~~~~~RouterOS update check: No new update available.~~~~~~~~~~~~"
}