[admin@test] > /system package update set channel=long-term
[admin@test] > :put [/system package update check-for-updates as-value]
channel=long-term;installed-version=6.48.4;latest-version=6.48.5;status=New version is available
This can be saved to an variable, and then you can test: if installed-version!=latest-version do something
This is not about doing it automatically.
All I want to know from my script is whether or not upgrade has been performed already and just a reboot is pending.
When the RouterOS upgrade, there will always be a boot firmware upgrade, and when there are no new RouterOS upgrade, there will not be a boot firmware upgrade, since the now follow each other 100%. Or I am wrong?
I still not understand what the goal is.
When your script sees a new updated RouterOS, then script upgrade it.
After upgrade/reboot, always upgrade firmware/reboot.
Not sure what you like to test for and why.
Would you like to test if boot firmware is change from before to after upgrade?
As I have written before, script should never ever do an upgrade by it self just because there there are a new RouterOS or boot firmware.
Test locally, test more, and even som more, read forum, wait some weeks ++. Then you can make a script start by looking at a web page and if web page says yes, do the upgrade.
What’s the added value besides the fact you DO have the ability to know that Upgrade+Reboot is needed (or possible instead of needed, depending on who’s looking at it) ?
Upgrade and Reboot is to be considered here as an entity. I agree it should be possible to have those two as separate status, but what’s the point ?
Not OP but I’ll add on to this.
Not everybody uses their routers the same way so it doesn’t really matter what the point of doing it is. The point is to learn how to do it.
In my case I’m going to have a lot of these routers in the field and I don’t want to have to log into each of them individually to see if a reboot is pending.
I’ll create a script that reports to my monitoring system which will tell me if a unit needs a reboot.
To answer OP’s question, there’s no elegant way to do it, but there is this:
{
/system/routerboard/print file=test;
:global x [/file get test.txt contents];
:if ([:find $x "please reboot"]) do={:put "yes";}
}
Note that $x in this case will be type nil if “please reboot” is not found, otherwise it will be number.
@eworm
I worked a bit on a script for what I imagine was your demand.
No ready yet, but is much better than my first version.
P.S.: I would like to use critical topic for logging, but its no possible.
Or at least I don't know how to do.
The "Magic" is on grep. grep got into list of supported commands just in 7.13, and correctly working on 7.14.
# RouterOS - Script "rebootForRouterBOARDFirmwareUpgrade"
# Tests if device needs reboot to apply routerboard Firmware Upgrade.
# Can do the reboot, or just do a forced warn with a login note.
# The correct functioning of this script depends on:
# - RouterOS Version 7 earlyer then 7.13/7.14 (uses grep command).
# - RouterBOARD firmware auto-upgrade feature being enabled.
# Following variable will define if reboot should be done, or just warn.
# If you really want that this device reboots to apply firmware upgrade you neet to set this variable as "IAuthorizeToReboot".
:local actionIfDetectRebootIsNeeded "IAuthorizeToReboot";
:local currentScriptName [:jobname];
:if ([:grep script="/system/routerboard/print" \
pattern="Firmware upgraded successfully, please reboot for changes"]!=0) do={
:global rebootForRouterBOARDFirmwareUpgradeIsNeeded true;
} else={
:global rebootForRouterBOARDFirmwareUpgradeIsNeeded false;
}
:if ([/system/routerboard/settings/get auto-upgrade] = true and rebootForRouterBOARDFirmwareUpgradeIsNeeded = true) do={
:if ($actionIfDetectRebootIsNeeded = "IAuthorizeToReboot") do={
:log warning "RouterBOARD firmware was upgraded by $currentScriptName script!"
:execute { /system reboot; }
} else={
:log warning "System note was overwrited by RouterBOARD $currentScriptName script!"
:execute { /system note set show-at-cli-login=yes show-at-login=yes \
note="RouterBoard Firmware needs attention!"; }
}
}