Community discussions

MUM Europe 2020
 
Genkun
newbie
Topic Author
Posts: 33
Joined: Mon Jul 27, 2015 11:32 am

Creating Semi-Automating ROS upgrade Script

Wed Jul 29, 2015 11:31 am

Hi

I am attempting to re-create a script I found on the wiki
http://wiki.mikrotik.com/wiki/Semi-Auto ... ng_changes

So far converting these to work on 6.29.1 with winbox 3.10rc12 is going okay.

I am having some trouble with the script and I use Notepad++ to do editing while I use New Terminal {} to see if all syntax errors are gone and I take away the {} to run the script through terminal directly.

My first issue I have run into is as follows: Red is Error Message I get, Italics/underline is alterations or Additions I made

/system script
:if ([find name="upgrade"]!="") do={remove [find name="upgrade"]}
add name=upgrade policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source=
:global NewV
:global pckgname
:global ntpname

/system upgrade refresh;

:delay 30s;

:set NewV [/system upgrade get [/system upgrade find name="routeros-mipsbe"] version]
invalid internal item number
:set pckgname ("routeros-mipsbe-". $NewV . ".npk")
:set ntpname ("ntp-". $NewV . "-mipsbe.npk")

:if ([/system upgrade get [/system upgrade find name="routeros-mipsbe"] status]!="installed") do={/system backup save;
:log error "Downloading Latest Version file - $pckgname";/system upgrade download [/system upgrade find name="routeros-mipsbe"];} else={:log
error "Latest Version file - $pckgname already installed";}
invalid internal item number

I am quite positive that the error might be with the get[version] but so far I have not found any ulterior under system upgrade. [latest-version] works in system packages.


I may add any further issues I run into while converting the rest.
Please feel free to comment on other or better ways to proof check scripts. I am noob.
 
Genkun
newbie
Topic Author
Posts: 33
Joined: Mon Jul 27, 2015 11:32 am

Re: Creating Semi-Automating ROS upgrade Script

Thu Jul 30, 2015 11:27 am

I have managed to find an alternative method to do the ROS which is effective. I just do not know how much bandwidth strain it would have if alll CPE's are initialized at once. Clearly a lot.


/system script
:if ([find name="packageupgrade"]!="") do={remove [find name="packageupgrade"]}
add name=packageupgrade policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source={
/system package update check-for-updates
:global oldver [/system package update get current-version];
:global newver [/system package update get latest-version];
:delay 20s

:if ([$oldver]<[$newver]) do={/system package update upgrade; :log error "RouterOS Upgrade commenced"}
}


This will then use mikrotiks servers to download the updates, but you will always get the latest and not be able to control which version is upgraded.

I was thinking if there is a way to time stamp sections of CPE's to run this script at separate interval times, which will be activated via a FTP trigger address. I know this will need schedulers to keep running. I was wondering if there is a way to do a netwatch which will trigger the scheduler to enable itself and auto-disable once the scheduler has run the script.

I will post my findings on this script process once i've made some progress.

Any input will be much appreciated.
 
Genkun
newbie
Topic Author
Posts: 33
Joined: Mon Jul 27, 2015 11:32 am

Re: Creating Semi-Automating ROS upgrade Script

Sat Aug 01, 2015 10:49 am

Regarding my last statement, I have decided to ficus more on what will be going onto the CPE. Here is an example with
an e-mail backup added in the case of a crash or corruption of data.

/system script
add name=rscfetch policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source={
:if ([:len [/file find name="upgrade.rsc"]] = 1) do={remove [/file find name="upgrade.rsc"]}
:global ftpserver
:global usrnme
:global passwd
:global pckgname
:set pckgname ("upgrade.rsc")
:set ftpserver "172.16.0.1"
:set usrnme "username"
:set passwd "password"

:if ([:len [/file find name="upgrade.rsc"]] = 0) do={
:log error "Downloading Upgrade File - $pckgname";/tool fetch address="$ftpserver" src-path="$pckgname" user="$usrnme" password="$passwd" mode=ftp;/import upgrade.rsc} else={
:log error "Upgrade File in Limbo";}

/system backup save name=email;
:delay 10s;
/tool e-mail send to="someone@someone.com" subject=([/system identity get name] . " Backup") file=email.backup;
:delay 10s;
/file remove email.backup
:delay 10s
/import file=upgrade.rsc
}


/tool netwatch
add disabled=no down-script="" host=172.16.0.1 interval=1m timeout=1s up-script=rscfetch;


Also any input would be much appreciated. I have two seperate if's that do very similar things. I was thinking of a nested if but so far I cannot seem to get it to work. If anyone could show an example of a nested if perhaps it would be greatly appreciated.
 
Genkun
newbie
Topic Author
Posts: 33
Joined: Mon Jul 27, 2015 11:32 am

Re: Creating Semi-Automating ROS upgrade Script

Mon Aug 03, 2015 9:40 am

This will probably be my last post on this thread. I understand that most of this script was taken from the link provided in post1. I want to thank the creator of that post and also the people who created the scripting ideas for such an innovative idea. I have learnt a lot from recreating and understanding the script and plan to work more on adding ideas to improve it for my specific needs.

Here I will post what essentially is the upgrade script package that will be imported on ftp trigger address 172.16.0.2

:if ([file find type=".rif file"]!="") do={/file remove [find type=".rif file"]}
:if ([file find type=".tar file"]!="") do={/file remove [find type=".tar file"]}
:if ([file find type=".npk file"]!="") do={/file remove [find type=".npk file"]}
:if ([file find type=".backup"]!="") do={/file remove [find type=".backup"]}
:if ([file find type=".rsc"]!="") do={/file remove [find type=".rsc"]}
/system backup save;
:delay 10s;


:if ([find name="upgrade"]!="") do={remove [find name="upgrade"]}
add name=upgrade policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source={
/system package update check-for-updates
:delay 20s
:global oldver [/system package update get current-version];
:global newver [/system package update get latest-version];

:if ([$oldver]<[$newver]) do={/system package update upgrade; :log error "RouterOS Upgrade commenced"}
}


:if ([find name="upgradefirm"]!="") do={remove [find name="upgradefirm"]}
add name=upgradefirm policy= ftp,reboot,read,write,policy,test,password,sniff,sensitive source={
:global oldfirm [/system routerboard get current-firmware];
:global newfirm [/system routerboard get upgrade-firmware];
:if ([$oldfirm]<[$newfirm]) do={:if ([/tool netwatch get [find host="172.16.0.4"] disabled]=yes) do={
/tool netwatch set [find host="172.16.0.4"] disabled=no;}}

:if ([$oldfirm]<[$newfirm]) do={/system routerboard upgrade;}
}


:if ([find name="rebooting"]!="") do={remove [find name="rebooting"]}
add name=rebooting policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source={
:if ([/tool netwatch get [find host="172.16.0.4"] disabled]=no) do={
/tool netwatch set [find host="172.16.0.4"] disabled=yes;}
:delay 20s;
system reboot;
}


:if ([find name="e-mail_backup"]!="") do={remove [find name="e-mail_backup"]}
add name=e-mail_backup policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source={
:log info "E-mail backup : Begin"

{/system backup save name=email; :delay 10s;
/tool e-mail send to="someone@someone.com" subject=([/system identity get name] . " Backup") file=email.backup;
:delay 10s; /file remove email.backup
:log info ("E-mail backup : Sent to Administrator at " . [/sys cl get time] . " " . [/sys cl get date])}
}


/tool netwatch
:if ([find host="172.16.0.2"]!="") do={remove [find host="172.16.0.2"]}
:if ([find host="172.16.0.3"]!="") do={remove [find host="172.16.0.3"]}
:if ([find host="172.16.0.4"]!="") do={remove [find host="172.16.0.4"]}
:if ([find host="172.16.0.5"]!="") do={remove [find host="172.16.0.5"]}
:if ([find host="172.16.0.2"]="") do={add disabled=no down-script="" host=172.16.0.2 interval=1m timeout=1s up-script=upgrade}
:if ([find host="172.16.0.3"]="") do={add disabled=no down-script="" host=172.16.0.3 interval=1m timeout=1s up-script=upgradefirm}
:if ([find host="172.16.0.4"]="") do={add disabled=yes down-script="" host=172.16.0.4 interval=1m timeout=1s up-script=rebooting}
:if ([find host="172.16.0.5"]="") do={add disabled=no down-script="" host=172.16.0.4 interval=1m timeout=1s up-script=e-mail_backup}



This script should be copy & paste into the terminal directly.

Who is online

Users browsing this forum: No registered users and 14 guests