So I created an import script which basically configures the Firewall , access lists , services , snmp , ntp , default password etc etc which works 100% but only under certain conditions So my technical guys will start off my updating to the latest firmware : 6.42.1(Stable) but they then have to "Reset the configuration" before the import script works properly... otherwise it will end up complaining about some missing items ... I'm guessing the default config that ships with the router is different then what you get when you reset the router to Default?
Anyway , after some troubleshooting I've realized that the following lines gets added when the router is defaulted. Well this and a bunch of other stuff changes but these two lines seems the only ones important to my issue
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
So normally this won't be an issue since it's a rather simple process , but every now and then our tech guys goes into retard mode and forgets to reset the router to default and also doesn't bother looking at the error which ends up in a poorly configured router.
So that said , I've been trying to add something in the script to check whether LAN or WAN is already added to the /interface list and if not to then add the missing values. So after reading through some scripting howtos I came up with the following code but I'm unable to get it to work. It basically needs to check whether the value is present and add it if missing. Problem is , I'm just getting an error "no such item" if it doesn't find the value which ends up with the (do) part not getting executed.
Check whether interface exist , if no value is returned
:if ([/interface list get WAN] = "") do { /interface list add comment=defconf name=WAN }
Sorry for the long windy post , just wanted to make sure I've added as much info as possible.
Is there perhaps a simple way of counting how many firewall rules are present ? I’m removing the firewall with the following script but it only works if I specify the correct amount of rules.
/for x from 1 to 10 do={/ip firewall filter remove $x}
Well, this one is a bit more complex. The reference numbers 0..n are only generated by the print command for your convenience, and their validity is limited until the first change which changes the number of the items in the list. These numbers are temporary aliases to pointers and the pointers seem to be static.
In my opinion, @mrz’s suggestion may fail on dynamic rules, but maybe the short form of
/ip firewall filter remove [find dynamic=no]
works. The only problem is that you never know in advance whether the command accepts the list returned by find directly or whether you need the foreach.
Thanks Sindy , I originally first tried what mrz suggested but the script stopped with the following error (failure: cannot remove builtin) which I’m guessing is the dynamic rule ?
Yes, if there are dynamic entries then [find dynamic=no] should be used. “foreach” in this case is unnecessary, it should be used if you want to edit specific rules or any other reason when you need to loop through all found entries.
Is there perhaps any specific rituals one needs to invoke to get the “Run after Reset” function to work when you specify a config script to get installed after “Resetting the config file” ? The script works with the normal import command via the terminal but dies somewhere leaving the router without an IP address if I use the “Run after reset” function. The log file also doesn’t provide any clues.
Delay is one option, but better option would be to wait for interfaces to load, for example if your config script depend on ethernet interfaces then do something like in code below.
@mrz (Martins?), If I get the above right, the script above implements a “clever delay” of up to 30 seconds - it ends succesfully as soon as the first ethernet interface appears, or fails with a warning if after 30 seconds still none of the ethers is created. But the OP’s problem is that even after 30 seconds the ethers are not present yet.
Hello guys, have a nice day!
Is there any way to count the system script source that contains specific variables?
Considering they have the same owner label. On the list below I want to count sources that contain “R1”.