Community discussions

MikroTik App
 
tedd77
newbie
Topic Author
Posts: 39
Joined: Sun Dec 18, 2011 5:05 pm

script stop on error

Fri Aug 03, 2018 1:46 am

Hello,
I have some scripts on my router to collect bad IP addresses from multiple files
Unfortunately the scripts stop upon error.
The error in all cases is that IP already exists . The IP could have been imported from an earlier file.

The error displayed in the log :
"script error failure already have such entry"

There is no way that I can check every file for duplicated IP, my database has over 7000 black-listed IP.
I seek a solution to ignore the error and continue the script execution.
Thank you for your help.
My router OS version is 6.42.6

this is one of my scripts: They all look the same but the file name is different

:foreach i in=[/ip firewall address-list find ] do={
:if ( [/ip firewall address-list get $i comment] = "IPblacklist1" ) do={
/ip firewall address-list remove $i
}
}
/import file-name=IPblacklist1.rsc;
:log info "Removal old IPblacklist1 and add new";

thank you in advance for your help
Last edited by tedd77 on Fri Aug 03, 2018 2:45 am, edited 3 times in total.
 
DaleNicholsSTG
just joined
Posts: 3
Joined: Fri Aug 03, 2018 1:47 am

Re: script stop on error

Fri Aug 03, 2018 2:32 am

:do has an on-error feature. This should work:
:foreach i in=[/ip firewall address-list find ] do={
  :if ( [/ip firewall address-list get $i comment] = "IPblacklist1" ) do={
    :do {
      /ip firewall address-list remove $i
    } on-error={}
  }
}
 
berzins
just joined
Posts: 10
Joined: Thu Apr 05, 2018 2:46 pm

Re: script stop on error

Fri Aug 03, 2018 1:08 pm

You can try to catch and ignore the error.

https://wiki.mikrotik.com/wiki/Manual:S ... ime_errors

It would look something like this.
:do {

:foreach i in=[/ip firewall address-list find ] do={
:if ( [/ip firewall address-list get $i comment] = "IPblacklist1" ) do={
/ip firewall address-list remove $i
}
}
/import file-name=IPblacklist1.rsc;
:log info "Removal old IPblacklist1 and add new";

} on-error={};
 
tedd77
newbie
Topic Author
Posts: 39
Joined: Sun Dec 18, 2011 5:05 pm

Re: script stop on error

Sat Aug 04, 2018 5:30 pm

Hello
Thank you all for your assistance and interaction.
I still have the same issue
Last edited by tedd77 on Sat Aug 04, 2018 8:51 pm, edited 1 time in total.
 
tedd77
newbie
Topic Author
Posts: 39
Joined: Sun Dec 18, 2011 5:05 pm

Re: script stop on error

Sat Aug 04, 2018 8:50 pm

Thank you all, still having the same error
Failure: already have such entry

I even simplified the code
:do {
/ip firewall address-list remove [/ip firewall address-list find comment=ipblacklist1]
/import file-name=ipblacklist1.rsc;
:log info "Removal old ipblacklist1 and add new";
} on-error={}

Even for fun I did this code , but I removed few entries to see if it wil work.still the same issue.
:do {
/import file-name=ipblacklist1.rsc;
:log info "Removal old ipblacklist1 and add new";
} on-error={}


I appreciate if you could try and let me know what code will work.
 
tedd77
newbie
Topic Author
Posts: 39
Joined: Sun Dec 18, 2011 5:05 pm

Re: script stop on error

Thu Aug 09, 2018 12:46 pm

Hello

It is a pity that I could not find a solution.
I had to rely on third party solution to do the job.
My problem is now temporarily solved.
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 209
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: script stop on error

Sat Aug 18, 2018 4:12 pm

the problem is inside "IPblacklist1.rsc"
can not add exist

you have 2 solution
remove all address list of "IPblacklist1" before import rsc file
or
you have to edit every line in rsc file like this example
:do {/ip firewall address-list
:do {add address=18.208.0.0/13 list=AWS comment="AWS-AMAZON"} on-error={}
:do {add address=52.95.245.0/24 list=AWS comment="AWS-AMAZON"} on-error={}
:do {add address=52.194.0.0/15 list=AWS comment="AWS-AMAZON"} on-error={}
:do {add address=54.155.0.0/16 list=AWS comment="AWS-AMAZON"} on-error={}

Who is online

Users browsing this forum: drpioneer, rogerioqueiroz and 26 guests