Page 1 of 1

AutoUpgrade script

Posted: Mon Feb 11, 2008 6:06 pm
by mrz
Anyone interested to upgrade routers automatically?
http://wiki.mikrotik.com/wiki/Auto_upgrade_script_V3.x
Comments, improvement suggestions are welcome.

Re: AutoUpgrade script

Posted: Thu Feb 21, 2008 6:09 pm
by DesertTek
Very Cool. We are trying it out now in our lab.

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 3:44 am
by davidw
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

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 7:13 am
by savage
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.

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 9:13 am
by mrz
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.

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 9:21 am
by savage
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 :)

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

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 9:33 am
by Chupaka
define "myVer" as global variable to be able to use it between different scripts (standalone Terminal commands are independent scripts)

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 9:38 am
by mrz
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] } }

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 10:03 am
by savage
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...

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 10:07 am
by mrz
What shows /system resource print?

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 10:29 am
by savage
[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

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 10:38 am
by mrz
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 <script-name>

and paste output here.

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 10:46 am
by savage
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>

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 10:49 am
by savage
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?

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 10:52 am
by mrz
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

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 10:54 am
by savage
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?

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

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 10:59 am
by savage
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] > 

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 10:59 am
by mrz
You can also add puts in for loop to check if characters are picked up correctly and that value from file is correct.

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 11:08 am
by savage
-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... </care> then.

Re: AutoUpgrade script

Posted: Mon Jun 15, 2009 12:50 pm
by mrz
**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
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.

Re: AutoUpgrade script

Posted: Fri Jun 19, 2009 5:49 pm
by fosben
Thanks, I like this script.

I was writing my own when I stumbled over this, and only had to do a few modifications. - And I dont download from Mikrotik automatically, I download the updates from my own server - because I want to test the new version before I apply it to ~250 clients..

Re: AutoUpgrade script

Posted: Fri Jul 24, 2009 6:03 am
by j2sw
Any hints on this script? I can't get it to run.
 /system script run Upgrade
interrupted
           bad name

Re: AutoUpgrade script

Posted: Fri Jul 24, 2009 10:00 am
by mrz
You have to add script named Upgrade :)

Re: AutoUpgrade script

Posted: Fri Jul 24, 2009 2:30 pm
by xezen
i know it not ment for this topic

but its almost the same

im looking for a script that does almost the same thing



but it must connect to remote server get file named
DNS.txt
in the file i have two lines

with 2 ip address

192.168.82.1
192.168.82.2

now how can i opne a remote file called DNS.txt
and read line 1 as primary dns
and line 2 as secondary dns

then chage the settings on that remote board and reboot the board when its done?


i cant get the reading part of the file right im no good with scripting??????

Re: AutoUpgrade script

Posted: Fri Jul 24, 2009 3:54 pm
by mrz
you have to download file first using fetch tool

then read file contents
/file get DNS.txt contents

then parse contents