Automatically check for MikroTik software updates
If you own multiple MikroTik devices (or even one) you already know how annoying and time consuming it is to keep checking if there are new updates available for your devices all the time.
The purpose of this tutorial is to help you setup your devices in order to receive an email notification if a new software update is available to download for your device.
Step 1
First of all, we need to setup the SMTP settings of your MikroTik device to allow it to send emails when required.
Using WinBox, or the web interface, navigate to Tools --> Email
and change your settings as shown in the image below. Please note that the image contains sample data and requires from you to change the settings with a working SMTP as well the correct credentials, if required.
If you prefer to use the CLI over the web interface or WinBox, you can use the command below:
1 | /tool e-mail set address=smtp.my-domain.com from=mikrotik@my-domain.com password=mypassword port=25 user=myusername |
Make sure to send a test email to verify that everything is working properly.
Step 2
Now that our MikroTik device is able to send emails it is time to create our script which will be responsible for checking for new updates and sending us an email if one is available.
Navigate to System --> Scripts
, click Add, change the title to “Check for software updates” or to something else if you prefer (don’t forget the name, you will need it in step 3) and finally, paste the following script in the source area:
1 2 3 4 5 6 7 8 9 10 11 | /system package update set channel=stable check-for-updates :if ([get installed-version] != [get latest-version]) do={ :log info "A new software update is available. Sending email..." /tool e-mail send to="$emailAddress" subject="[Mikrotik] Software Update Available" body="A new update is available for your MikroTik device" } |
CLI Version (pay attention to the highlighted line)
1 2 3 4 5 6 7 8 9 10 11 12 13 | /system script add name="Check for software updates" owner=<your username> policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":local emailAddress \"[email protected]\"\r\ \n\r\ \n/system package update\r\ \nset channel=stable\r\ \ncheck-for-updates\r\ \n\r\ \n:if ([get installed-version] != [get latest-version]) do={ \r\ \n:log info \"A new software update is available. Sending email...\"\r\ \n\r\ \n/tool e-mail send to=\"\$emailAddress\" subject=\"[Mikrotik] Software Update Available\" body=\"A new update is available for your Mikrotik device\"\r\ \n}\r\ \n" |
Step 3
It is time for the last step. In order for everything to work properly, we need to trigger our script every now and then in order for the update check to take place. To accomplish this, we will use the scheduler feature which is located under System --> Scheduler
Simply add a new scheduled task, give it a name and specify how often it should run in the interval section (I run mine with a 2d 00:00:00 interval).
In the “On Event” section paste the line below.
1 | /system script run "Check for software updates" |
Important: Make sure the name of the script is exactly the same as the one you have created in step 2!
CLI Version
1 2 | /system scheduler add interval=2d name="Check for software update" on-event="/system script run \"Check for software updates\"" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=dec/24/2016 start-time=00:00:00 |
And you are done! If you have successfully followed this example your MikroTik device will check every 2 days for new updates and will let you know by email if one is available.
This method has been tested in the last few versions of RouterOS (currently 6.38). For older versions you might need to alter the script functions a bit to get everything working correctly.
If you have any questions don’t hesitate to ask them in the comment section below.
Update: As of v6.43.7 the release channels have been renamed. If you want to use the above script on a MikroTik that is running an older RouterOS version you will need to use the old software update channel name.
For RouterOS equal or newer than v6.43.7
1 | set channel=stable |
For RouterOS older than v6.43.7
1 | set channel=current |
* release channels renamed – “bugfix” to “long-term”, “current” to “stable” and “release candidate” to “testing”
here is another script for automatic update and backup to an email
https://github.com/beeyev/Mikrotik-RouterOS-automatic-backup-and-update
My version of script that runs on the latest 6.44.3 version is:
Script no longer works since version 6.43.7 (2018-Nov-30).
This is because the release channels have been renamed.
In order to fix the script, change the following line:
‘set channel=current’
to
‘set channel=stable’
You are correct Freek, thanks for letting us know. I’ve updated the post to reflect the changes.
My script version looks like:
Works for me on 6.42.3 …
no longer works in 6.42.6 The check-for-updates command causes subsequent command lines to be lost while the check is performed. Trying to introduce a :delay 15s; line is not a solution as this line gets ‘eaten’ by the check-for-updates command
Can’t replicate this in the terminal since everything seems to be working as expected there. I will let you know as soon as an update becomes available.
I’ve tested it with the new version that was just released (6.42.7) and everything seems to be working
You need update script:
/system package update
check-for-updates once
:delay 1s;
:if ( [get status] = “New version is available”) do={…
Thank you very much! Works great