Community discussions

MikroTik App
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

"Firmware upgraded successfully..." from script

Mon Nov 22, 2021 1:08 pm

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?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: "Firmware upgraded successfully..." from script

Mon Nov 22, 2021 2:20 pm

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
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: "Firmware upgraded successfully..." from script

Mon Nov 22, 2021 3:01 pm

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?
 
holvoetn
Forum Guru
Forum Guru
Posts: 5472
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: "Firmware upgraded successfully..." from script

Mon Nov 22, 2021 4:20 pm

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 ??
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: "Firmware upgraded successfully..." from script

Mon Nov 22, 2021 5:08 pm

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.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: "Firmware upgraded successfully..." from script

Mon Nov 22, 2021 7:09 pm

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?
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: "Firmware upgraded successfully..." from script

Mon Nov 22, 2021 10:09 pm

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?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: "Firmware upgraded successfully..." from script

Mon Nov 22, 2021 10:45 pm

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.
 
User avatar
eworm
Forum Guru
Forum Guru
Topic Author
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: "Firmware upgraded successfully..." from script

Tue Nov 23, 2021 10:27 am

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?
 
holvoetn
Forum Guru
Forum Guru
Posts: 5472
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: "Firmware upgraded successfully..." from script

Tue Nov 23, 2021 10:38 am

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 ?
 
alfred998
Frequent Visitor
Frequent Visitor
Posts: 76
Joined: Fri Apr 27, 2018 4:58 pm

Re: "Firmware upgraded successfully..." from script

Tue Nov 23, 2021 11:13 am

[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


So what you are looking for is how to retrieve that notice or what triggers it.
 
LaZyLion
newbie
Posts: 32
Joined: Fri May 09, 2014 10:27 am

Re: "Firmware upgraded successfully..." from script

Thu Jun 22, 2023 6:32 pm

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: "Firmware upgraded successfully..." from script

Thu Jun 22, 2023 7:22 pm

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
}

Who is online

Users browsing this forum: eldoncito2019 and 20 guests