Auto upgrade MikroTik RouterOS & Firmware

By | 8.3.2021
  • Script pro automatický upgrade RouterOS a Firmware s upozorněním na e-mail
  • Stačí vložit do Schelduleru nebo do Scripts
:local FWcurrent [/system routerboard get current-firmware]
:local FWupgrade [/system routerboard get upgrade-firmware]
:local RBname [/system identity get name]
:local d [/system clock get date]
:local t [/system clock get time]
### Pro upgrade ROS
/system package update
check-for-updates once
:delay 3s
:if ( [get status] = "New version is available") \
do={ \
:log info "Nova verze ROS je dostupna, stahuji..." 
:tool e-mail send to=muj@mail.cz subject="Upgrade RoS - $n" body="$n - $t $d"
install 
:log info "Restartuji..." 
} \
else={ \
:log info "Aktualni ROS, kontroluji aktualnost Firmware..." 
### Pro upgrade Firmware
:if ($FWcurrent = $FWupgrade) \
       do={ \
      :log info "Aktualni Firmware" \
       } \
      else={ \
      :log info "Neaktualni Firmware" 
      :delay 2 
      :log info "Nastavuji upgrade" 
      /system routerboard upgrade
      :delay 10 
      :log info "Restartuji..."
      /system reboot
      } 
} 

Kompletní kod, bez upozornění na e-mail do terminálu pro vložení Schelduleru se spuštěním po startu s opakováním každý týden

/system scheduler
add interval=1w name="upgrade ROS" on-event=":local FWcurrent [/system routerboard get current-firmware]\r\
 \n:local FWupgrade [/system routerboard get upgrade-firmware]\r\
 \n### Pro upgrade ROS\r\
 \n/system package update\r\
 \ncheck-for-updates once\r\
 \n:delay 3s\r\
 \n:if ( [get status] = \"New version is available\") \\\r\
 \ndo={ \\\r\
 \n:log info \"Nova verze ROS je dostupna, stahuji...\" \r\
 \ninstall \r\
 \n:log info \"Restartuji...\" \r\
 \n} \\\r\
 \nelse={ \\\r\
 \n:log info \"Aktualni ROS, kontroluji aktualnost Firmware...\" \r\
 \n### Pro upgrade Firmware\r\
 \n:if (\$FWcurrent = \$FWupgrade) \\\r\
 \n do={ \\\r\
 \n :log info \"Aktualni Firmware\" \\\r\
 \n } \\\r\
 \n else={ \\\r\
 \n :log info \"Neaktualni Firmware\" \r\
 \n :delay 2 \r\
 \n :log info \"Nastavuji upgrade\" \r\
 \n /system routerboard upgrade\r\
 \n :delay 10 \r\
 \n :log info \"Restartuji...\"\r\
 \n /system reboot\r\
 \n } \r\
 \n} \r\
 \n" policy=reboot,read,write,policy,test,password,sensitive start-time=startup

Napsat komentář

Vaše emailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *