I recently logged into my router to find this at the top of my log:-

However, I didn’t get an email. Why? Because the router was still resolving items with the modem and my modem was still resolving stuff with my ISP. I basically want to have something along the lines of:-
preSendEmail(email emailObject) {
boolean resolved = false;
while(!resolved) {
try {
resolve("google.com", false);
//If the above fails, it'll throw an exception and exit this try clause before getting here
resolved = true;
} catch(Exception e) {
//I really don't care what the exception is aslong as there is one.
}
}
sendEmail(email);
}
Where:-
sendEmail(email emailObject); = the function that sends the email
resolve(string domain, boolean useCache); = the function that resolves the address, note the useCache = false
try{}catch(){} = the try clause
So far here’s what’s stopping me:-
A. No way to not use the cache for the resolve, from what I can see.
B. No way to catch on an exception, the second resolve throws “failure: dns server failure” the script dies
Anyone know how to do it?
EDIT Still no dice with:-
{
:local domain "google.com"
:log info "start";
:put "start";
:local resolved false;
{do {:log info "resolving"; :put "resolving"; :resolve $domain; :log info "resolved"; put "resolved"; :set resolved true;} while (!resolved);}
:log info "done";
:put "done";
}
With google.com:-
[admin@MikroTik] /system script> run test
start
resolving
resolved
done
With g:-
start
resolving
failure: dns name does not exist
I don’t know why I thought putting it in it’s only clause with the {} would help, but, eh.
EDIT:- I even tried multiple scripts, no cigar:-
emailOne:-
#Variables
#domain to test
:global domain "smtp.gdmsdafdsafail.com";
#boolean that marks if domain has been resolved
:global resolved false;
#/Variables
#loop while google can't be resolved
:do {
#Debug
:put "Running second script";
#Run second script to resolve, no try clause in routerOS
/system script run emailTwo;
#Debug
:put "Ran second script"
} while (!$resolved);
:put "Resolve worked!";
emailTwo:-
#Assign domain, else it doesn't "exist" in this process
:global domain;
#Assign resolved, same as above
:global resolved;
#Resolve domain
:resolve $domain;
#If the resolve failed, the script will have already returned, so, we assume the resolve worked.
:set resolved true;
Output:-
[admin@MikroTik] /system script> /system script run emailOne
Running second script
failure: dns name does not exist
EDIT:-
:execute seems to work, as proved by this log (Modem was unplugged for the first half):-
[admin@MikroTik] /system script> /system script run emailOne
Running second script
Ran second script
Running second script
Ran second script
Running second script
Ran second script
Running second script
Ran second script
Running second script
Ran second script
Running second script
Ran second script
Running second script
Ran second script
Running second script
Ran second script
Done
Only issue is that it seems to run it in a different thread and doesn’t wait for it, which, means that I have to do something like this:-
#Variables
#domain to test
:global domain "smtp.gmail.com";
:global domain "google.com"
#boolean that marks if domain has been resolved
:global resolved false;
#/Variables
#loop while google can't be resolved
:do {
#Debug
:put "Running second script";
#Run second script to resolve, no try clause in routerOS
#/system script run emailTwo;
:execute emailTwo
delay 1s
#Debug
:put "Ran second script"
} while (!$resolved);
:put "Done";
Anyway to have it wait for it? Instead of delaying?



