"Firmware upgraded successfully..." from script

Hello everybody,

updating the firmware (/system routerboard upgrade) writes a notice in log and adds a comment in the menu.

Firmware upgraded successfully, please reboot for changes to take effect!

But is there a way to make a script get that information about pending firmware update?

You can run it some like this in a script.

[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

I am not interested in RouterOS, I know how that works.
My issue is with boot firmware:

[admin@jupiter] > :put [ /system routerboard get ]
current-firmware=6.49;factory-firmware=3.41;firmware-type=tilegx;model=CCR1009-7G-1C-1S+;routerboard=true;serial-number=849708XXXXXX;upgrade-firmware=6.49.1

Can you tell if the upgrade for 6.49.1 is pending?

Conceptually:
Current-firmware <> upgrade-firmware → upgrade.

In your example:
6.49 <> 6.49.1, so upgrade would be required.

Given all recent mishaps, is it a good idea to do this automagically ??

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?

Yes, there’s always an upgrade available.
I want to know if the upgrade has been applied already. First situation:

[admin@Mikrotik] > /system routerboard print 
       routerboard: yes
             model: CCR1009-7G-1C-1S+
     serial-number: 849708XXXXXX
     firmware-type: tilegx
  factory-firmware: 3.41
  current-firmware: 6.49
  upgrade-firmware: 6.49.1

Second situation:

[admin@Mikrotik] > /system routerboard print 
                ;;; Firmware upgraded successfully, please reboot for changes to take effect!
       routerboard: yes
             model: CCR1009-7G-1C-1S+
     serial-number: 849708XXXXXX
     firmware-type: tilegx
  factory-firmware: 3.41
  current-firmware: 6.49
  upgrade-firmware: 6.49.1

How to tell the difference from script?

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.

Ok, let’s try something different.
What I want is:

[admin@Mikrotik] > :put [ /system routerboard get pending-reboot-for-upgrade ]
true

But something like that does not exist, no?

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 ?

So what you are looking for is how to retrieve that notice or what triggers it.

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.

Can be created also one script for SNMP…

{
/sys rou print file="tmptest.txt"
/file
:local thefile [find where name="tmptest.txt"]
:if ([:len [:find [get $thefile contents] "please reboot"]] > 0) do={:put "REBOOT"} else={:put "OK"}
/file remove $thefile
}