AVA Studio ID

lisensi

Iklan

AVA Studio
30 December 2022, 14:55 WITA (GMT+8)
Last Updated 2022-12-30T06:55:28Z

Script Mikrotik RouterOS - Auto upgrade script V3.xxx

Advertisement
Script  Mikrotik RouterOS - Auto upgrade script V3.xxx


An automatic upgrade script is a script that is designed to automatically check for and install updates for a particular piece of software or system. This can be useful in a variety of situations, such as keeping a network of devices up to date with the latest security patches or ensuring that a software application is always running the most recent version.
  1. To create an automatic upgrade script, you will need to write a script that performs the following steps:
  2. Check for updates: This step involves using a command or API provided by the software or system you are working with to check for updates.
  3. Determine if an update is available: Once the update check is complete, you will need to determine whether an update is available. This may involve comparing the current version of the software or system with the latest available version.
  4. Download and install the update: If an update is available, your script should download and install it. This may involve using a command or API provided by the software or system, or it may involve downloading the update from a remote server and installing it manually.
  5. Optionally, you may also want to include steps to handle error cases, such as if the update check fails or if the update is not available.
One small script to automatically update RrouterBoards.
-) Get a file from the main router containing the latest ROS version number. -) Get the current version number. -) Extract and compare minor and major version numbers. -) Download the merged package directly from mikrotik.com if the version you got from your main router is the latest version. -) Restart your computer. First you need to create a file with the latest version number on your main router.

/file print file="latestVer";

/file set latestVer.txt content="3.24";

Now we're ready to run scripts on other routers:

#########################################################################
# Download and upgraded
#########################################################################

# newest version
:local lMajor;
:local lMinor;

# current version
:local vMajor;
:local vMinor;

:local myVer [/system resource get version];

:for i from=0 to=([:len $myVer] - 1) do={
:if ( [:pick $myVer $i] = ".") do={
:set vMajor [:tonum [:pick $myVer 0 $i]];
:set vMinor [:tonum [:pick $myVer ($i + 1) [:len $myVer]]] ;
}
}

:if ($vMajor < 3) do={
:log warning "RouterOS version too old ($vMajor.$vMinor), update script not compatible";
} else={

# detect platform (architecture-name is not available in older 3.x versions)
:local platform [/system resource get architecture-name];

# fetch latest version
/tool fetch address="172.16.0.1" src-path="latestVer.txt" user="admin" password="" mode=ftp;
:local lVer [/file get latestVer.txt content];

:for i from=0 to=([:len $lVer] - 1) do={
:if ( [:pick $lVer $i] = ".") do={
:set lMajor [:tonum [:pick $lVer 0 $i]];
:set lMinor [:tonum [:pick $lVer ($i + 1) [:len $lVer]]] ;
}
}

:if (($vMajor = $lMajor) && ($vMinor < $lMinor)) do={
:local pckgName "routeros-$platform-$lMajor.$lMinor.npk";
/tool fetch address=[:resolve "www.mikrotik.com"] host="www.mikrotik.com" mode=http src-path="download/$pckgName";
/system reboot;
} else={
:log info "Upgrade_script: already latest version";
}
}

No comments:

Post a Comment

Selamat Datang

X
X