AutoUpgrade script

Anyone interested to upgrade routers automatically?
http://wiki.mikrotik.com/wiki/Auto_upgrade_script_V3.x
Comments, improvement suggestions are welcome.

Very Cool. We are trying it out now in our lab.

Hi There,

I was trying to get this script to run but having problems with the script stopping after the first fetch command has run.

Its like it ignores all subsequent commands.

Anyone else had similar problems ?

Cheers

Not working on 3.23, nor on 4beta3… Haven’t tested on 3.24 as it is a bit pointless trying to upgrade a router which is already on the latest version.

You have to modify script if you want to upgrade from 3.x to 4.0beta. look at the code and you will understand why.

Now, that’s not what I said :slight_smile:

Anways…

[admin@Client] > :for i from=0 to=([:len $myVer] - 1) do={  
syntax error (line 1 column 26)

define “myVer” as global variable to be able to use it between different scripts (standalone Terminal commands are independent scripts)

Ofcourse it is syntax error, because in your case variable “myVer” is not defined.

Try this one

{ :local myVer "3.24"; :for i from=0 to=([:len $myVer] - 1) do={  :put [:pick $myVer $i] } }

Hi,

I suggest you make some mentions on the wiki - the script needs to be modified, and the script ONLY works if you have the BASE package installed. It does not work for individual packages…

08:54:54 info fetch: file "latestVer.txt" created 
08:54:55 script,info Upgrade_script: already latest version

Yet…

[admin@Client] /system package> /file print detail 
 0 name="latestVer.txt" type=".txt file" size=5 creation-time=jun/15/2009 08:53:10 contents=3.24 
[admin@Client] /system package> /system package print 
Flags: X - disabled 
 #   NAME                                                                         VERSION                                                                         SCHEDULED              
 0   system                                                                       3.23                                                                                                   
 1   security                                                                     3.23                                                                                                   
 2   multicast                                                                    3.23                                                                                                   
 3   advanced-tools                                                               3.23                                                                                                   
 4   dhcp                                                                         3.23                                                                                                   
 5   ppp                                                                          3.23

And your problem:

		:local pckgName "routeros-$platform-$lMajor.$lMinor.npk";
		/tool fetch address=[:resolve "www.mikrotik.com"] host="www.mikrotik.com" mode=http src-path="download/$pckgName";

I’d suggest that you change that to check for each package individually as well… I for one, don’t upload packages to routers where they aren’t needed…

Thank you…

What shows /system resource print?

[admin@Client] > /system resource print 
                   uptime: 3h25m47s
                  version: "3.23"
              free-memory: 246184kB
             total-memory: 256540kB
                      cpu: "AMD"
                cpu-count: 1
            cpu-frequency: 2611MHz
                 cpu-load: 0
           free-hdd-space: 171087kB
          total-hdd-space: 202059kB
  write-sect-since-reboot: 1370
         write-sect-total: 1370
        architecture-name: "x86"
               board-name: "x86"
[admin@Client] > /system package pr
Flags: X - disabled 
 #   NAME                                                                         VERSION                                                                         SCHEDULED              
 0   system                                                                       3.23                                                                                                   
 1   security                                                                     3.23                                                                                                   
 2   multicast                                                                    3.23                                                                                                   
 3   advanced-tools                                                               3.23                                                                                                   
 4   dhcp                                                                         3.23                                                                                                   
 5   ppp                                                                          3.23                                                                                                   
[admin@Client] > /file print detail 
 0 name="latestVer.txt" type=".txt file" size=5 creation-time=jun/15/2009 08:54:54 contents=3.24 
[admin@Client] >

Im pretty sure you’ll need to do something in line of

:foreach i in [/system package find ] do {:log info [/system package find $i name]}

But ROS scripting has never been my strong point…

EDIT You are specifically looking for the routeros-platform-version package, and also just downloading that one package. There is no accomodation in this script for people using individual packages, instead of the one single combined package. I guess that’s the point I’m trying to make

it doesn’t matter if i check version of every package or getting version number from system resources
In your case it shows
version: “3.23”

And if file contains 3.24 then script should work.

add following lines

:put $vMajor;
:put $vMinor;
:put $lMajor;
:put $lMinor;

before

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

then run script from terminal

/system script run

and paste output here.

Doesn’t do anything - very strange indeed…

[admin@Client] > /system script run script1 ;




  status: connecting
                                                                                                                                                                                         
  status: finished
[admin@Client] > /system script export 
# jun/15/2009 09:45:43 by RouterOS 3.23
# software id = 85UF-SRT
#
/system script
add name=script1 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source="#########################################################################\r\
    \n# download and upgrade\r\
    \n#########################################################################\r\
    \n\r\
    \n# newest version\r\
    \n:local lMajor;\r\
    \n:local lMinor;\r\
    \n\r\
    \n# current version\r\
    \n:local vMajor;\r\
    \n:local vMinor;\r\
    \n\r\
    \n:local myVer [/system resource get version];\r\
    \n\r\
    \n:put \$vMajor;\r\
    \n:put \$vMinor;\r\
    \n:put \$lMajor;\r\
    \n:put \$lMinor;\r\
    \n\r\
    \n\r\
    \n:for i from=0 to=([:len \$myVer] - 1) do={  \r\
    \n\t:if ( [:pick \$myVer \$i] = \".\") do={ \r\
    \n\t\t:set vMajor [:tonum [:pick \$myVer 0 \$i]]; \r\
    \n\t\t:set vMinor [:tonum [:pick \$myVer (\$i + 1) [:len \$myVer]]] ;\r\
    \n\t}\r\
    \n}\r\
<SNIP>

Moved it to below the first for loop… and,

[admin@Client] > /system script run script1 ;
3
23


  status: connecting
                                                                                                                                                                                         
  status: finished

So, it doesn’t read the file correctly?

of course in your case they will output empty line, because values are not set yet.

please place all put’s right before

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

as I mentioned in previous post

Which is where it is!

: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]]] ;
	}
}

:put $vMajor;
:put $vMinor;
:put $lMajor;
:put $lMinor;

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

Output:

[admin@Client] > /system script run script1 ;
3
23


  status: requesting
                                                                                                                                                                                         
  status: finished

Moved it down further now to after the fetching was done…

#      fetch latest version
       /tool fetch address="192.168.1.254" src-path="Applications/Mikrotik/latestVer.txt" user="ftp" 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]]] ;
		}
	}

:put $vMajor;
:put $vMinor;
:put $lMajor;
:put $lMinor;

and

[admin@Client] > /system script run script1 ;
  status: requesting
                                                                                                                                                                                         
  status: finished
3
23
3

[admin@Client] >

You can also add puts in for loop to check if characters are picked up correctly and that value from file is correct.

-yawn-

maybe i’ll just stick to ncftpput then and run it from a scripting language that’s been proven to work then and has some actual error checking…

FYI - there are TWO LINES exactly the same “:if (($vMajor = $lMajor) && ($vMinor < $lMinor)) do={” however, read my posts, you’ll see there’s a second post, where the output has been given to you before both of them.

Oh well anyways… then.

I am using combined package for upgrade and it meets my requirements perfectly. I shared the script so that others may find it useful.

If it doesn’t meet your requirements you are welcome to modify the script - to download separate packages, for example.