Community discussions

 
Manuel86
just joined
Topic Author
Posts: 4
Joined: Fri Aug 31, 2018 10:35 am

Auto update ROS / routerboard fm from my FTP Server

Fri Sep 14, 2018 9:14 am

Hi,

First sry for my english :) is not the best.
and I am not a programmer !!!

I have build a script for all my new Mikrotik Routers. I have more then 1000 Router in Europe but without remote access.
In the future i will stop this with my script. I can say over my ftp server witch ROS version i will download all Routers or i change very easy on all Routers the password or other settings.

I have the script success tested well with v.6.40.8 and 6.40.9

Update:
on my FTP Server play 3 Files:
version.txt -> content: 6.40.9
update.txt -> content: routeros-mipsbe-6.40.9.npk
and the update File: routeros-mipsbe-6.40.9.npk

Add this code in the schedule with startup and interval 2d or 1w:
{
:delay 10s
:tool fetch url="ftp://your-domain.com/update.txt" mode=ftp user=YYYYYY password=XXXXXXXXXXXXXXX
:delay 5s
:tool fetch url="ftp://your-domain.com/version.txt" mode=ftp user=YYYYYY password=XXXXXXXXXXXXXXX
:delay 5s
:local rosupdate [file get update.txt contents ]
:local versionnumber [file get version.txt contents ]
:local actualversionnumber [/system package update get installed-version]
:delay 1s
:file remove update.txt
:file remove version.txt
:if ([$actualversionnumber] != ([$versionnumber])) do={
:tool fetch url="ftp://your-domain.com/$rosupdate" mode=ftp user=YYYYYY password=XXXXXXXXXXXXXXX
:log warning "!!! Download finished ! Router OS $rosupdate / Router restart in the night 04:00:00 !!!"
:delay 5s
:system script run nightreboot
} else={
:local fmrouterboard [/system routerboard get current-firmware]
:local newfmrouterboard [/system routerboard get upgrade-firmware]
:if ([$fmrouterboard] != ([$newfmrouterboard])) do={
:system routerboard upgrade
:log warning "!!! Routerboard firmware updated / Router restart in the night 04:00:00 !!!"
:delay 5s
:system script run nightreboot
}}}

and we need a second script for the restart only in the night. Scriptname: nightreboot
{
:local fecha [/system clock get date]
:local dia [ :pick $fecha 4 6 ]
:local mes [ :pick $fecha 0 3 ]
:local year [ :pick $fecha 7 11 ]
:local newdia ($dia + 1)
:local newyear ($year + 1)

:if ($fecha = "jan/31/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="feb/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "feb/28/$year" or $fecha = "feb/29/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="mar/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "mar/31/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="apr/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "apr/30/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="may/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "may/31/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="jun/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "jun/30/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="jul/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "jul/31/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="aug/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "aug/31/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="sep/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "sep/30/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="oct/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "oct/31/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="nov/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "nov/30/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="dec/01/$year" start-time="04:00:00"
} else {
:if ($fecha = "dec/31/$year") do={
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="jan/01/$newyear" start-time="04:00:00"
} else {
:system scheduler add name=reboot on-event="/system scheduler remove reboot; /system reboot" start-date="$mes/$newdia/$year" start-time="04:00:00"
}}}}}}}}}}}}
}
if you have sntp cleint activ, is the restart only in the night 04:00:00

Have you a better idea, please tell me.
 
Manuel86
just joined
Topic Author
Posts: 4
Joined: Fri Aug 31, 2018 10:35 am

Re: Auto update ROS / routerboard fm from my FTP Server

Fri Sep 14, 2018 9:22 am

one better idea is when i not delete the version.txt and update.txt and i check the file of the server date and time with the file on the mikrotik.

but no plan for the script :)

Who is online

Users browsing this forum: altucor and 7 guests