Community discussions

MikroTik App
 
jakir69
just joined
Topic Author
Posts: 12
Joined: Mon Feb 06, 2017 9:00 am

Need to enable/disable Interface

Tue Nov 09, 2021 2:26 pm

Hello Everyone, I am using mikrotik crs328p. What i want to do achieve is
if interface=ether1 is enable and in running state then interface=ether2 should be disabled
if interface=ether1 is enabled but link status is down then interface=ether2 should be enabled automatically
if the interface=ether1 comes in running state back then interface=ether=2 should go in disabled state
can i achieve this using script and scheduler
if yes i am unable create a script that works
any help would be much appreciated.
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 725
Joined: Tue Dec 17, 2019 1:08 pm

Re: Need to enable/disable Interface

Tue Nov 09, 2021 3:04 pm

Very Basic Script-Exemple...
:if ((![/interface ethernet get ether1 disabled]) && ([/interface ethernet get ether1 running])) do={
# Interface is Enabled AND Interface is Running
/interface ethernet set ether2 disabled=yes
} else={:if ((![/interface ethernet get ether1 disabled]) && (![/interface ethernet get ether1 running])) do={
# Interface is Enabled and NOT Running
/interface ethernet set ether2 disabled=no
}
}
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Need to enable/disable Interface

Tue Nov 09, 2021 8:26 pm

Same code, just rewritten some:
/interface ethernet 
:if ((![get ether1 disabled]) && ([get ether1 running])) do={
	# Interface is Enabled AND Interface is Running
	set ether2 disabled=yes
} else={
	:if ((![get ether1 disabled]) && (![get ether1 running])) do={
		# Interface is Enabled and NOT Running
		set ether2 disabled=no
	}
}
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 725
Joined: Tue Dec 17, 2019 1:08 pm

Re: Need to enable/disable Interface

Tue Nov 09, 2021 8:39 pm

Thank you @Jotne
It really makes the Script less bloated and easier to read!!

Who is online

Users browsing this forum: No registered users and 30 guests