Community discussions

MikroTik App
 
akarpas
Member Candidate
Member Candidate
Topic Author
Posts: 177
Joined: Tue Mar 20, 2018 4:46 pm

cant get X OR Y AND Z properly working

Tue Mar 09, 2021 5:55 pm

:if ([/ping 1.1.1.1 count=5] !=0 || [/ping 2.2.2.2 count=5] != 0 && [/interface vrrp get vrrp2 priority]=90) do={[/interface vrrp set vrrp2 priority=150]}

let's say if to change vrrep2 priority to 155 on a line to test if this line works. So by the logic, if host A or Host B is pingable AND vrrp2 priority = 90 script line should change the priority to 150 but if priority is already 150 it should do nothing as didn't meet requirements. But it's not working if I change, set priority to 155 it will set it with the next script run even priority is 150, not 90.
 
Emil66
Frequent Visitor
Frequent Visitor
Posts: 62
Joined: Tue Aug 28, 2018 2:09 am

Re: cant get X OR Y AND Z properly working

Tue Mar 09, 2021 6:05 pm

Note that (A || B && C) means (A || (B && C)) due to operator precedence, not ((A || B) && C). If you want the latter, you need to use parentheses as shown. It's like 1+2*3 is 7, not 9.
 
akarpas
Member Candidate
Member Candidate
Topic Author
Posts: 177
Joined: Tue Mar 20, 2018 4:46 pm

Re: cant get X OR Y AND Z properly working

Tue Mar 09, 2021 6:29 pm

Note that (A || B && C) means (A || (B && C)) due to operator precedence, not ((A || B) && C). If you want the latter, you need to use parentheses as shown. It's like 1+2*3 is 7, not 9.
Emil thanks a mill for clearing this, changed it as per your explanation and it works now the way it should :).
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: cant get X OR Y AND Z properly working

Tue Mar 09, 2021 6:42 pm

Just to show how complicate order of precedence is.

What is the result of: 60/5(7-5)

10 or 24
 
akarpas
Member Candidate
Member Candidate
Topic Author
Posts: 177
Joined: Tue Mar 20, 2018 4:46 pm

Re: cant get X OR Y AND Z properly working

Tue Mar 09, 2021 6:46 pm

BODMAS just went out of my mind then it came to Mikrotik scripting :D I'm new to Mikrotik scripting but with your help guys doing progress. Thanks a mill again.

Who is online

Users browsing this forum: No registered users and 14 guests