RouterOS Italia

Versione completa: [Mikrotik] Auto upgrade script V3.x
Al momento stai visualizzando i contenuti in una versione ridotta. Visualizza la versione completa e formattata.
One little script to upgrade RrouterBoards automatically.
  • ) fetch file from main router containing latest ROS version number;
  • ) get currently running version number;
  • ) extract minor and major version numbers and compare them;
  • ) if version fetched from main router is newer then download combined package directly from mikrotik.com
  • ) reboot.
At first you should create file containing newest version number on main router.

Codice:
/file print file="latestVer";
/file set latestVer.txt content="3.24";
Now we are ready to run scripts on other routers:
Codice:
#########################################################################

Codice:
# download and upgrade

Codice:
#########################################################################


Codice:
# newest version

Codice:
:local lMajor;

Codice:
:local lMinor;


Codice:
# current version

Codice:
:local vMajor;

Codice:
:local vMinor;


Codice:
:local myVer [/system resource get version];


Codice:
:for i from=0 to=([:len $myVer] - 1) do={  

Codice:
    :if ( [:pick $myVer $i] = ".") do={

Codice:
        :set vMajor [:tonum [:pick $myVer 0 $i]];

Codice:
        :set vMinor [:tonum [:pick $myVer ($i + 1) [:len $myVer]]] ;

Codice:
:if ($vMajor < 3) do={

Codice:
    :log warning "RouterOS version too old ($vMajor.$vMinor),  update script not compatible";

Codice:
} else={


Codice:
#      detect platform (architecture-name is not available in older 3.x versions)

Codice:
      :local platform [/system resource get architecture-name];



Codice:
#      fetch latest version

Codice:
      /tool fetch address="172.16.0.1" src-path="latestVer.txt" user="admin" password="" mode=ftp;

Codice:
      :local lVer [/file get latestVer.txt content];



Codice:
    :for i from=0 to=([:len $lVer] - 1) do={  

Codice:
        :if ( [:pick $lVer $i] = ".") do={

Codice:
            :set lMajor [:tonum [:pick $lVer 0 $i]];

Codice:
            :set lMinor [:tonum [:pick $lVer ($i + 1) [:len $lVer]]] ;

Codice:
        }

Codice:
    }


Codice:
    :if (($vMajor = $lMajor) && ($vMinor < $lMinor)) do={

Codice:
        :local pckgName "routeros-$platform-$lMajor.$lMinor.npk";

Codice:
        /tool fetch address=[:resolve "www.mikrotik.com"] host="www.mikrotik.com" mode=http src-path="download/$pckgName";

Codice:
        /system reboot;

Codice:
    } else={

Codice:
               :log info "Upgrade_script: already latest version";

Codice:
       }

Codice:
}


Add scheduler to run this script, for example once in 24h (or whatever interval you like).