The DHCP server has a predictable way of giving out the ip's. So, I thought, why not use that feature.
I made a csv in Excel an named it AP.txt. It contains an IP adres with a name. Don't forget to give a enter after the last line in notepad!!!
AP.txt
AP57,192.17.16.221
AP58,192.17.16.222
AP59,192.17.16.223
AP60,192.17.16.224
AP61,192.17.16.225
AP62,192.17.16.226
AP63,192.17.16.227
And so on...
Don't forget about the max file size of 4K.
I made sure that I could read the file, so I copied it to a RB2011 and executed this scrip from the terminal.
:global content [/file get AP.txt contents ];
:global contentLen [:len $content ];
:global lineEnd 0;
:global line "";
:global lastEnd 0;
do {
:set lineEnd [:find $content "\r\n" $lastEnd ];
:set line [:pick $content $lastEnd $lineEnd];
:set lastEnd ( $lineEnd + 2 );
:global tmpArray [:toarray $line];
:if ( [:pick $tmpArray 0]!= "" ) do={
:put [:pick $tmpArray 0];
:put [:pick $tmpArray 1];}
} while ($lastEnd < $contentLen)
I left in the globals to see how the script executed. You can see the output in /system/script/environment.
Since that was working I can pick out a name (APxx) thanks to the ip address. The script below is already kind of production ready so it won't give an output.
:global content [/file get AP.txt contents ];
:global contentLen [:len $content ];
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:global apname [:pick [/ip address get 0 address] 0 [:find [/ip address get 0 address ] "/"]];
do {
:set lineEnd [:find $content "\r\n" $lastEnd ];
:set line [:pick $content $lastEnd $lineEnd];
:set lastEnd ( $lineEnd + 2 );
:global tmpArray [:toarray $line];
:if ( [:pick $tmpArray 0]!= "" ) do={
:if ("$apname"= [:pick $tmpArray 1]) do={
/system identity set name=[:pick $tmpArray 0];
/ip dhcp-client remove 0;
/ip address add address=[:pick $tmpArray 1] netmask=255.255.254.0 interface=BridgeVlan99
}
}
} while ($lastEnd < $contentLen)
Ok, here goes.
What I want is:
-CPE must be upgraded to whatever version
-Unneeded packages should be disabled
-Set IP and hostname.
What I did
-Set up dhcp server with exact range of CPE's to roll out
-Made a script for flashfig with a basic config and the following script in it.
-flashfigged the CPE's and kicked of this script with netwatch. Just to make sure that there is an IP connection.
:local DHCPDisabled [/system package get dhcp disabled];
:local MyVersion [/system resource get version];
:local WantedVersion "6.36.4 (bugfix)";
if ($DHCPDisabled=false) do={
:if ($MyVersion=$WantedVersion) do={
/system package enable [/system package find name="system"]
/system package disable [/system package find name="ipv6"]
/system package enable [/system package find name="wireless"]
/system package disable [/system package find name="hotspot"]
/system package disable [/system package find name="dhcp"]
/system package disable [/system package find name="mpls"]
/system package disable [/system package find name="routing"]
/system package disable [/system package find name="ppp"]
/system package enable [/system package find name="security"]
/system package enable [/system package find name="advanced-tools"]
/tool fetch address=192.17.16.190 src-path=AP.txt mode=ftp user=FTP password=FTP
:delay 10
:global content [/file get AP.txt contents ];
:global contentLen [:len $content ];
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:global apname [:pick [/ip address get 0 address] 0 [:find [/ip address get 0 address ] "/"]];
do {
:set lineEnd [:find $content "\r\n" $lastEnd ];
:set line [:pick $content $lastEnd $lineEnd];
:set lastEnd ( $lineEnd + 2 );
:global tmpArray [:toarray $line];
:if ( [:pick $tmpArray 0]!= "" ) do={
:if ("$apname"= [:pick $tmpArray 1]) do={
/system identity set name=[:pick $tmpArray 0];
/ip dhcp-client remove 0;
/ip address add address=[:pick $tmpArray 1] netmask=255.255.254.0 interface=BridgeVlan99
}
}
} while ($lastEnd < $contentLen)
:foreach i in=[/system script find] do={ :if ([:typeof [:find [/system script get $i name] "Step2"]]!="nil") do={/system script remove $i};}
:if ([/tool netwatch find host="192.17.16.190"]!="") do={/tool netwatch remove [find host="192.17.16.190"]}
/system reboot
} else={
/tool fetch address=192.17.16.190 src-path=routeros-mipsbe-6.36.4.npk mode=ftp user=FTP password=FTP
:delay 10
/system reboot
}
}
What does it do;
-It checks (netwatch) if an ip is up and starts script
-Checks if the dhcp client is running
-Checks if the OS version is ok. If not.. FTP
-Reboot
-It checks (netwatch) if an ip is up
-Checks if the dhcp client is running
-Checks if the OS version is ok.
-Disable the packages that I don't need
-Gets a name via the script that reads AP.txt.
-Kills itself and the netwatcher.
-Reboots
Took me 1 hour to do 40 units.