Community discussions

MikroTik App
 
mattiejshill
just joined
Topic Author
Posts: 6
Joined: Fri Apr 22, 2022 4:57 pm

One click provisioning

Thu Sep 22, 2022 9:40 pm

Background:
I work for an ISP. When customers cancel their service, I receive their routers, wipe the config, and replace it with the latest config we are using. Currently, I have to plug into each router individually and send the files over. I'm using FTP with an auto.rsc file to run a script that wipes the router and then does "run after reset=". What I would like to do is provision them all with one click. The issue is that until now I have not been able to write a script that accomplishes this because all of the routers have the same default private IP address of 192.168.88.1. I was pretty sure I had figured out how to get around this today but I can't seem to get it to work.

My setup:
I am currently using an hAP with 4 other hAPs connected via ethernet. I have all the ether interfaces disabled except for one. This way when I send a file to 192.168.88.1 there will only be one pathway and the file will go to the hAP that I want.

Method:
I am attempting to write a simple script that will send a file from one MikroTik router to another using FTP. Once the file is sent it should disable the interface it used and enable the next interface making this new interface the only route to 192.168.88.1. The problem I am having is that after the file is sent through FTP it seems that the rest of the script is not executed. The issue seems to have something to do with the FTP part of the script because when I run it sending a different command like ping it runs through the whole script with no problem.
/tool/fetch address=192.168.88.1 upload=yes dst-path=/flash/HapConfigFTP.rsc src-path=/flash/HapConfigFTP.rsc mode=ftp user=*** password=***
/tool/fetch address=192.168.88.1 upload=yes dst-path=/flash/ResetHAPConfig.auto.rsc src-path=/flash/ResetHAPConfig.auto.rsc mode=ftp user= *** password=***
/interface disable ether2
/interface enable ether3
/ip arp remove [find]
ping 192.168.88.1 count=15

/tool/fetch address=192.168.88.1 upload=yes dst-path=/flash/HapConfigFTP.rsc src-path=/flash/HapConfigFTP.rsc mode=ftp user=*** password=***
/tool/fetch address=192.168.88.1 upload=yes dst-path=/flash/ResetHAPConfig.auto.rsc src-path=/flash/ResetHAPConfig.auto.rsc mode=ftp user= *** password=***
/interface disable ether3
/interface enable ether4
/ip arp remove [find]
ping 192.168.88.1 count=15

/tool/fetch address=192.168.88.1 upload=yes dst-path=/flash/HapConfigFTP.rsc src-path=/flash/HapConfigFTP.rsc mode=ftp user=*** password=***
/tool/fetch address=192.168.88.1 upload=yes dst-path=/flash/ResetHAPConfig.auto.rsc src-path=/flash/ResetHAPConfig.auto.rsc mode=ftp user= *** password=***
/interface disable ether4
/interface enable ether5
/ip arp remove [find]
ping 192.168.88.1 count=15

/tool/fetch address=192.168.88.1 upload=yes dst-path=/flash/HapConfigFTP.rsc src-path=/flash/HapConfigFTP.rsc mode=ftp user=*** password=***
/tool/fetch address=192.168.88.1 upload=yes dst-path=/flash/ResetHAPConfig.auto.rsc src-path=/flash/ResetHAPConfig.auto.rsc mode=ftp user= *** password=***
/interface disable ether5
/interface enable ether2
The script only gets through the second line. I know because I can hear the router reboot and can see that the configuration has been uploaded.

If I run this script all the step are followed.
/interface disable ether2
/interface enable ether3
/ip arp remove [find]
ping 192.168.88.1 count=15

/interface disable ether3
/interface enable ether4
/ip arp remove [find]
ping 192.168.88.1 count=15

/interface disable ether4
/interface enable ether5
/ip arp remove [find]
ping 192.168.88.1 count=15

/interface disable ether5
/interface enable ether2

The router I am using to run the script is running ROS v7.5

Can someone please explain why the code execution stops after the files are sent?

Thank you!
 
mattiejshill
just joined
Topic Author
Posts: 6
Joined: Fri Apr 22, 2022 4:57 pm

Re: One click provisioning  [SOLVED]

Fri Sep 23, 2022 12:20 am

Well, I figured out what the problem was. When the config.auto.rsc file gets sent over it is immediately executed, which is what I wanted, but evidently it does not gracefully close down the FTP connection so an error is thrown and the script stops execution.

I added some error handling to fix it. I wanted to use a for loop with a variable that increases representing the interface number but couldn't figure out how to get error handling to work with a for loop.
:do {/tool fetch address=192.168.88.1 upload=yes dst-path=/flash/ResetHAPConfig.auto.rsc src-path=/flash/ResetHAPConfig.auto.rsc mode=ftp user=*** password=***;} on-error={interface disable ether2; interface enable ether3}
interface disable ether2
interface enable ether3
ip arp remove [find]
ping 192.168.88.1 count=15

:do {/tool fetch address=192.168.88.1 upload=yes dst-path=/flash/ResetHAPConfig.auto.rsc src-path=/flash/ResetHAPConfig.auto.rsc mode=ftp user=*** password=***;} on-error={interface disable ether3; interface enable ether4}
interface disable ether3
interface enable ether4
ip arp remove [find]
ping 192.168.88.1 count=15

:do {/tool fetch address=192.168.88.1 upload=yes dst-path=/flash/ResetHAPConfig.auto.rsc src-path=/flash/ResetHAPConfig.auto.rsc mode=ftp user=*** password=***;} on-error={interface disable ether4; interface enable ether5}
interface disable ether4
interface enable ether5
ip arp remove [find]
ping 192.168.88.1 count=15

:do {/tool fetch address=192.168.88.1 upload=yes dst-path=/flash/ResetHAPConfig.auto.rsc src-path=/flash/ResetHAPConfig.auto.rsc mode=ftp user=*** password=***;} on-error={interface disable ether5; interface enable ether2}
interface disable ether5
interface enable ether2
ip arp remove [find]
I added the "interface disable ether" lines after the on-error command just incase it decided not to throw an error. I still wanted the action to take place. And fortunately telling an interface to shutdown or to be enabled twice doesn't throw an error.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: One click provisioning

Fri Sep 23, 2022 1:06 am

Work for a ISP?

Why use such absurd and complicated "solutions", when there are quicker methods to configure, even in bulk???

Why don't you run netinstall with the "Configure Script" option???
 
mattiejshill
just joined
Topic Author
Posts: 6
Joined: Fri Apr 22, 2022 4:57 pm

Re: One click provisioning

Fri Sep 23, 2022 6:42 am

I’m very new to MikroTIk can you explain more?

And personally I think it was a pretty ingenuitive idea for just jumping in and figuring out a solution that works lol. Now that it’s set up all I have to do is plug in the routers and literally click one button.

I’ve used netinstall to fix a few routers that got stuck in a boot loop but it was a major pain to get netinstall to even recognize that the router was there. I tried all the suggestions and it only worked after switching computers twice.

Furthermore, if I have to put each router into etherboot mode to use netinstall that would take far longer than my solution.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: One click provisioning

Fri Sep 23, 2022 10:43 am

It take less time than enable ftp on CPE.

But...

Something suggest me that the ftp service is enabled on your CPEs... :?

Who is online

Users browsing this forum: No registered users and 12 guests