Last active
May 2, 2025 18:27
-
-
Save gretel/98f70ef3be00d8143df9c28f58cd66a1 to your computer and use it in GitHub Desktop.
mikrotik routeros update check script - based on https://ondra.sluka.cz/posts/2023-06-13-mikrotik-check-for-updates/ but more robust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check for updates and mail admin if available | |
:local emailAddress "[email protected]" | |
# Set the update channel and check for updates | |
/system package update set channel=development | |
/system package update check-for-updates | |
# Get current version information | |
:local currver [/system package update get installed-version] | |
:local newver [/system package update get latest-version] | |
:local status [/system package update get status] | |
# Get the script ID first to properly reference it | |
:local scriptID [/system script find where name="check-for-updates"] | |
:if ([:len $scriptID] = 0) do={ | |
:log warning "Script 'check-for-updates' not found" | |
} else={ | |
# Get the current comment value | |
:local lastnotifver [/system script get $scriptID comment] | |
# Debug output to log | |
:log info "Debug - currver: $currver, newver: $newver, lastnotifver: $lastnotifver, status: $status" | |
# Always update the comment with the current version, regardless of status | |
/system script set $scriptID comment=$newver | |
:log info "Updated script comment to: $newver" | |
# Only send email if there's a new version available | |
:if ($currver != $newver and $newver != $lastnotifver) do={ | |
:log info "Software update available ($currver -> $newver). Sending email..." | |
:local hostname [/system identity get name] | |
/tool e-mail send to="$emailAddress" subject="[$hostname] Software Update Available: $newver" \ | |
body="A new update is available for your MikroTik device: $currver -> $newver" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/system scheduler add interval=1d name=check-for-updates on-event=check-for-updates policy=read,write,policy,test start-date=may/1/2025 start-time=16:00:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment