Good afternoon,
I have been searching but without success, my knowledge is not much and I would like to thank the community for help with the following.
I have a script that checks every day for RouterOs updates. and send me an email
I wanted this script to save the new version on disk (Txt) and whenever it is run it checks what is in this file and if the new version is the same as the one in the file it does nothing.
Basically what I want is to stop receiving an email every day with the update notification, I wanted to only receive one email per new update version.
I leave my script. Once again, I would like to thank the more experienced people for their help on this topic.
:local emailAddress “email@gmail.com”
:local nomedohost [/system identity get name];
/system package update
set channel=stable
check-for-updates once
:delay 3s;
:local newversion [get latest-version];
: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="[$nomedohost] New update ($newversion) available " body=“A new update is available for your MikroTik device.
New Version : $newversion”
} else={ :log info " RouterOS no Update Available ***” }
The best idea is to test RouterOS separately, and when in the lab it seems to work correctly at least for 3 months, apply it to a small part in production, for testing, and if it goes well plan the update everywhere.
So it doesn’t matter to be notified when there is a new version of RouterOS, just look on the forum or the site.
99.9% of security bugs are avoided simply by configuring the devices correctly (aka firewall and usual and known security measures that are valid everywhere).
@panisk0
The global variable suggestion is perfect.
The problem is who on the other side doesn’t understand it.
You just have to finish explaining what you think…
@MC88
If you set a global variable with the latest detected version,
when you recheck, if it is already identical to the latest detected version, you do nothing,
otherwise you send the email and set the latest detected version to the new value.
This way the number of writes to the internal memory is not consumed either.
Other methods, for one reason or another, cause wearing on internal NAND/Flash memory.
Do not download the new version in advance. It just fills the disk. You need it only when you upgrade.
/system package update
set channel=stable
check-for-updates once
:delay 3s;
:local newversion [get latest-version]
:local oldversion [get installed-version]
:if ($newversion!=$oldversion) do={
:log info "*** A new software update $newversion is available. Sending email..."
} else={
:log info "*** RouterOS no update current $oldversion is available ***"
}
Thanks,
How do I define the global variable and put this condition in the example
/system package update
set channel=stable
check-for-updates once
:delay 3s;
:local newversion [get latest-version]
:local oldversion [get installed-version]
:if ($newversion!=$oldversion) do={
:log info "*** A new software update $newversion is available. Sending email..."
New Version : $newversion"
} else={
:log info "*** RouterOS no update current $oldversion is available ***"
}
What the global variable is needed for except the fact that you are not remainded that version is outdated every time the script is run?
If ones wants to know that router is outdated then it should be remainded periodically not only when router is restarted or the new release is published. No need to run the script more often than once a week or even month.
Or better… If the scheduler name is checkVersion, simply disable it once send the email…
{
/system package update
:local test [check-for-updates as-value]
:local installed ($test->“installed-version”)
:local latest ($test->“latest-version”)
:if ($installed!=$latest) do={
:log warning “Is installed RouterOS $installed but is available version $latest”
# /tool e-mail …
}
/system scheduler disable “checkVersion”
}