Community discussions

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

else -if

Tue Mar 02, 2021 3:15 pm

Can I use if after else?
if (safsafasfasfasfasfa);
else:
if(safasfsafasfasf)
or its not possible in Mikrotik scripting?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: else -if

Tue Mar 02, 2021 3:31 pm

Yes you can use as many if and else you like.

Example
:if (version>=6.5) do={
	# Do some stuff
} else={
	# Do some other stuff
	:if (host=27) do={
		# Do some other stuff here
	}
}
 
akarpas
Member Candidate
Member Candidate
Topic Author
Posts: 177
Joined: Tue Mar 20, 2018 4:46 pm

Re: else -if

Tue Mar 02, 2021 3:48 pm

Yes you can use as many if and else you like.

Example
:if (version>=6.5) do={
	# Do some stuff
} else={
	# Do some other stuff
	:if (host=27) do={
		# Do some other stuff here
	}
}
Thanks, just another question is the syntax ok if I want to ping host A and B and both are down switch of C
:if ([/ping 10.10.200.1 count=5] AND [/ping 10.10.100.1 count=5] = 0) do={[/interface disable ether8]} this line doesn work its switches off ether if one or other is down
and if A or B is accessible switch C back online
:if ([/ping 10.10.200.1 count=5] | [/ping 10.10.100.1 count=5] != 0) do={[/interface enable ether8]} this line works perfect
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: else -if

Tue Mar 02, 2021 11:26 pm

Script can be used to nearly all tings, but do not use ping to test for ip up, use netwatch.
https://wiki.mikrotik.com/wiki/Manual:Tools/Netwatch

Do search forum here for example
 
akarpas
Member Candidate
Member Candidate
Topic Author
Posts: 177
Joined: Tue Mar 20, 2018 4:46 pm

Re: else -if

Wed Mar 03, 2021 1:05 am

Script can be used to nearly all tings, but do not use ping to test for ip up, use netwatch.
https://wiki.mikrotik.com/wiki/Manual:Tools/Netwatch

Do search forum here for example
yeh i understand but i want to test two host instead of one before taking some action
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: else -if

Wed Mar 03, 2021 8:07 am

Then you just use and &&
:if ($test1="true"&&test2="true") do={
   # do some here
}
PS no need to quote the whole post above your. Use Post Reply button at the bottom of the post
 
akarpas
Member Candidate
Member Candidate
Topic Author
Posts: 177
Joined: Tue Mar 20, 2018 4:46 pm

Re: else -if

Wed Mar 03, 2021 4:22 pm

Jotne thank you, this worked like a charm no I have a simple script with two hosts check-up and different do scenarios, I really appreciate your advice's.

Who is online

Users browsing this forum: Maxfadeev699 and 21 guests