Community discussions

MikroTik App
 
16mc
newbie
Topic Author
Posts: 31
Joined: Tue Dec 15, 2009 8:55 pm

Import on restart not working

Tue Jan 12, 2010 12:14 am

I have created a script for configuring our CPE's. I can cut and past to the command line and it works fine. If I import from the command line it works.

I exported the config and then attempted to reset and import the script using /system reset run-after-reset=file.rsc does not work. Tried calling a file that just does an import no go either. Write a short file with a couple of commands to set ip, works fine. Been messing with it all day and it seems to be a hit and miss with mostly misses. Reading the post there appeared to be issues with some versions of 3.x and fixed by 3.30. I have tried 4.2 and 4.4 with no success, is this still an issue?

I need to put standard configs on several hundred clients and this seem to be a good way to do it as I need to delete firewall setting etc. and there are various configs so a reset seem the simplest way.


Any input would be helpfull
 
changeip
Forum Guru
Forum Guru
Posts: 3833
Joined: Fri May 28, 2004 5:22 pm

Re: Import on restart not working

Tue Jan 12, 2010 2:54 am

how big is the script in bytes? what happens if you set a delay at the beginning of the script of 5-10s?
 
Prairiekid
just joined
Posts: 9
Joined: Fri Nov 27, 2009 11:56 pm

Re: Import on restart not working

Wed Mar 10, 2010 11:37 pm

What are the odds? I was trying to get this working yesterday afternoon, and found that it would run partially through the exported script, but not all the way. Did you get an answer to this problem. I would like this to work as well to clean up some messy configs that are out there on some of my old radios. Past in our new config called "install" and then run after reset to repair any issues. In theory this should work.
 
missinlnk
Member Candidate
Member Candidate
Posts: 113
Joined: Wed Aug 13, 2008 8:10 pm

Re: Import on restart not working

Thu Mar 11, 2010 1:40 am

I always have to clean up our scripts that have been exported before they will import correctly. The easiest way to troubleshoot the script is to copy/paste it into a terminal. Scroll back up in the terminal and you should find at least one error message in the middle of your script. That error should tell you enough to allow you to fix the problem. Many times it's a line that isn't relevant to your custom config and that line can just be removed completely from your rsc file.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Import on restart not working

Thu Mar 11, 2010 4:11 pm

also, if you are trying to set up something like wireless interface settings, it may fail, even if syntax is ok and you are setting up sane things, the problem is - if you try to set up that is not yet initialized it will fail, like with wireless - it is initialized last, so, when you try to set up something on wireless interface that is there when everything boots up, interface is just not there.
try to add some delay or something.
 
pedja
Long time Member
Long time Member
Posts: 687
Joined: Sat Feb 26, 2005 5:37 am

Re: Import on restart not working

Fri Mar 12, 2010 3:42 pm

It would be better if MT would load script after everything is initialized. That is what most of us would expect.

But, bigger problem is that when you export script, you usually cannot import it back without syntax errors.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7198
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Import on restart not working

Fri Mar 12, 2010 3:45 pm

I was able to export, reset config and import config back without errors.
Contact support and specify which part of configuration is not importing.
 
Prairiekid
just joined
Posts: 9
Joined: Fri Nov 27, 2009 11:56 pm

Re: Import on restart not working

Sat Mar 13, 2010 1:19 am

I did get it working as well following some of these suggestions. Added the 10 second delay, and then added one section at a time until I found the config items that were breaking the script. Seams to be that it doesn't want to add my user settings, as well as accepting the line where the Admin password is changed. Everything else worked, which is good enough for me at the moment because at least my radio reconnects to the system. At this point I have only a few manual changes to enter.
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: Import on restart not working

Sat Mar 13, 2010 6:50 am

I too find that direct exports need modifications sometimes to correctly import.
This is usually because interfaces are set using the number (0, 1, 2) as they appear on startup.
It's usually best to setup a script to detect known values (mac address, ip address, etc...) or clear a config sub-menu before creating any rules.

As a rule of thumb, I try to put checks in where ever possible:
# Wait for wireless to come up
/interface wireless
{
   :while ([:len find] = 0) do={ :delay 1 }
#  at this point, we found at least one wireless interface. do some actions...
}

# To set an interface's name
/interface ethernet
{
   :if ([:len find mac-address="00:11:22:33:44:55"] > 0) do={
#    set interface name.  this allows filter rules that use interface name to import correctly
      /interface ethernet set [find mac-address="00:11:22:33:44:55"] name="LAN"
   }
   :if ([:len find mac-address="55:44:33:22:11:00"] > 0) do={
#    set interface name.  this allows filter rules that use interface name to import correctly
      /interface ethernet set [find mac-address="55:44:33:22:11:00"] name="WAN"
   }
}

# Remove all firewall
/ip firewall
{
# remove all firewall -> filter, nat, mange, and address-list rules to start with clean slate
   filter {
      :foreach r in=[find] do={ remove $r }
#    add new rules
   }
   nat {
      :foreach r in=[find] do={ remove $r }
#    add new rules
   }
   mangle {
      :foreach r in=[find] do={ remove $r }
#    add new rules
   }
   address-list {
      :foreach r in=[find] do={ remove $r }
#    add new rules
   }
}
Hope this is useful. With some error-checking, scripting can be quite reliable.