Community discussions

MikroTik App
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

AutoUpgrade script

Mon Feb 11, 2008 6:06 pm

Anyone interested to upgrade routers automatically?
http://wiki.mikrotik.com/wiki/Auto_upgrade_script_V3.x
Comments, improvement suggestions are welcome.
 
DesertTek
newbie
Posts: 43
Joined: Sun Feb 10, 2008 9:10 am

Re: AutoUpgrade script

Thu Feb 21, 2008 6:09 pm

Very Cool. We are trying it out now in our lab.
 
davidw
Frequent Visitor
Frequent Visitor
Posts: 91
Joined: Fri Apr 27, 2007 11:11 pm

Re: AutoUpgrade script

Mon Jun 15, 2009 3:44 am

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
 
savage
Forum Guru
Forum Guru
Posts: 1220
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 7:13 am

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.
Regards,
Chris
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 9:13 am

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.
 
savage
Forum Guru
Forum Guru
Posts: 1220
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 9:21 am

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)
Regards,
Chris
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8394
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 9:33 am

define "myVer" as global variable to be able to use it between different scripts (standalone Terminal commands are independent scripts)
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 9:38 am

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] } }
 
savage
Forum Guru
Forum Guru
Posts: 1220
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 10:03 am

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...
Regards,
Chris
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 10:07 am

What shows /system resource print?
 
savage
Forum Guru
Forum Guru
Posts: 1220
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 10:29 am

[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
Regards,
Chris
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 10:38 am

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.
 
savage
Forum Guru
Forum Guru
Posts: 1220
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 10:46 am

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>
Regards,
Chris
 
savage
Forum Guru
Forum Guru
Posts: 1220
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 10:49 am

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?
Regards,
Chris
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 10:52 am

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
 
savage
Forum Guru
Forum Guru
Posts: 1220
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 10:54 am

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
Regards,
Chris
 
savage
Forum Guru
Forum Guru
Posts: 1220
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 10:59 am

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] > 
Regards,
Chris
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 10:59 am

You can also add puts in for loop to check if characters are picked up correctly and that value from file is correct.
Last edited by mrz on Mon Jun 15, 2009 11:16 am, edited 1 time in total.
 
savage
Forum Guru
Forum Guru
Posts: 1220
Joined: Mon Oct 18, 2004 12:07 am
Location: Cape Town, South Africa
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 11:08 am

-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.
Regards,
Chris
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: AutoUpgrade script

Mon Jun 15, 2009 12:50 pm

**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.
 
fosben
Frequent Visitor
Frequent Visitor
Posts: 81
Joined: Thu Dec 14, 2006 4:50 pm

Re: AutoUpgrade script

Fri Jun 19, 2009 5:49 pm

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..
 
User avatar
j2sw
Member Candidate
Member Candidate
Posts: 111
Joined: Mon Sep 04, 2006 5:42 am
Location: Indiana
Contact:

Re: AutoUpgrade script

Fri Jul 24, 2009 6:03 am

Any hints on this script? I can't get it to run.
 /system script run Upgrade
interrupted
           bad name
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: AutoUpgrade script

Fri Jul 24, 2009 10:00 am

You have to add script named Upgrade :)
 
xezen
Long time Member
Long time Member
Posts: 628
Joined: Fri May 30, 2008 10:23 am
Location: South Africa

Re: AutoUpgrade script

Fri Jul 24, 2009 2:30 pm

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??????
If i dont No Ask someone That Does!
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 6045
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: AutoUpgrade script

Fri Jul 24, 2009 3:54 pm

you have to download file first using fetch tool

then read file contents
/file get DNS.txt contents

then parse contents

Who is online

Users browsing this forum: No registered users and 23 guests