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.