Disable/enable eth ports using ping

I need to create a simple script for server failover.

Scenario

ether 3–enabled --server a— ip 98.123.123.123 public ip with dns pointed to it
ether 4–disabled–server b— ip 98.123.123.123 public ip with dns pointed to it

Script would ping ether 3 ip address.
If it is fails for a specified period of time
ether 3 disabled
eher 4 disabled
email sent to adminstrator to inform him of changes

:slight_smile: :frowning:

Thanks for your help as i could not find a similar script in the examples.

Can you try if this is what you are looking for?
:if ([/ping 98.123.123.123 interface=ether3 count=3] = 0) do={
:log info “disabling interfaces”
[/interface disable ether3]
[/interface disable ether4]
}

HI i reallize i made a typo. I meant

Scenario

ether 3–enabled --server a— ip 98.123.123.123 public ip with dns pointed to it
ether 4–disabled–server b— ip 98.123.123.123 public ip with dns pointed to it

Script would ping ether 3 ip address.
If it is fails for a specified period of time
ether 3 disabled
ether 4 enabled
email sent to administrator to inform him of changes

Would the script be as follows?

ros code
1 :if ([/ping 98.123.123.123 interface=ether3 count=3] = 0) do={
2 :log info “disabling interface 3 enabling interface 4”
3 [/interface disable ether3]
4 [/interface enable ether4]
5 }

You are right. Sending emails can be done with just one line, but you need to configure your smtp server in Winbox under Tools > Email first.

:if ([/ping 98.123.123.123 interface=ether3 count=3] = 0) do={
:log info “disabling interface 3 enabling interface 4”
[/interface disable ether3]
[/interface enable ether4]
/tool e-mail send to=“test@gmail.com” subject=“test” body=(“email contents”) tls=yes
}

Hi,

I have tried the script below without success. I am not sure how to enable the logs any further to tell me why, but it appears that the script doesnt work. I have unplugged the device in ether3, and nothing else occurs. I even tried amending the script to remove the whitespace after count-3, without any different results.

Here it is again.


:if ([/ping 192.168.88.254 interface=ether3 count=3]=0) do={
:log info “disabling interface 3 enabling interface 4”
[/interface disable ether3]
[/interface enable ether4]
}

Do you possibly have ether3 in a bridge interface, or does ether3 have a master port on your router? What is your setup?

Now the router doesnt work at all and i cannot get into it with mac or otherwise it is an rb20111. This is unbelievably frustrating.

Try a different port. Maybe the script disabled the port and it is inactive, thus you can’t access the device through it.

I dont understand why nothing works.
The only thing i did was change the subnet on the dhcp address from /24 to /28.

Since then nothing works on any ports, even the ones on the first five ports that had no ips assigned to it.

There is no reset button on this router so i guess now it is a paper weight.

This is unbelievably frustrating.

For some reason, after plugging in my computer to many ports, it worked all of a sudden. I was able to reset the config and start over. My setup is as follows:

Please explain to me what i am doing wrong. The bridge is inactive for eth2-5 and i have no idea why!

Flags: D - dynamic, X - disabled, R - running, S - slave

NAME TYPE MTU L2MTU MAX-L2MTU

0 R ether1-gateway ether 1500 1598 4074
1 S ether2 ether 1500 1598 4074
2 R ether3 ether 1500 1598 4074
3 R ether4 ether 1500 1598 4074
4 S ether5 ether 1500 1598 4074
5 RS ether6-master-local ether 1500 1598 2028
6 S ether7-slave-local ether 1500 1598 2028
7 S ether8-slave-local ether 1500 1598 2028
8 S ether9-slave-local ether 1500 1598 2028
9 S ether10-slave-local ether 1500 1598 2028
10 R bridge-local bridge 1500 1598
[
[admin@MikroTik] > ip dhcp-server print
Flags: X - disabled, I - invalid

NAME INTERFACE RELAY ADDRESS-POOL LEASE-TIME ADD-ARP

0 default bridge-local default-dhcp 3d
[admin@MikroTik] > ip dhcp-server network print

ADDRESS GATEWAY DNS-SERVER WINS-SERVER DOMAIN

0 ;;; default configuration
192.168.88.0/24 192.168.88.1 192.168.88.1
[admin@MikroTik] > ip pool print

NAME RANGES

0 default-dhcp 192.168.88.2-192.168.88.15
[admin@MikroTik] > ip route print
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit

DST-ADDRESS PREF-SRC GATEWAY DISTANCE

0 ADS 0.0.0.0/0 192.168.2.1 1
1 ADC 192.168.2.0/24 192.168.2.0 bridge-local 0
2 DC 192.168.2.0/24 192.168.2.108 ether1-gateway 0
3 ADC 192.168.88.0/24 192.168.88.252 ether4 0
ether3

++++FOR SOME REASON THE ETHER3 ADDRESS OF 192.168.88.254 DOESNT SHOW UP IN THIS+++++

Flags: X - disabled, R - running
0 R name="bridge-local" mtu=1500 l2mtu=1598 arp=enabled
mac-address=D4:CA:6D:31:B1:63 protocol-mode=rstp priority=0x8000
auto-mac=no admin-mac=D4:CA:6D:31:B1:63 max-message-age=20s
forward-delay=15s transmit-hold-count=6 ageing-time=5m
[admin@MikroTik] > interface bridge port print
Flags: X - disabled, I - inactive, D - dynamic

INTERFACE BRIDGE PRIORITY PATH-COST HORIZON

0 I ether2 bridge-local 0x80 10 none
1 I ether5 bridge-local 0x80 10 none
2 ether6-master-local bridge-local 0x80 10 none
3 I ether3 (unknown) 0x80 10 none
4 I ether4 (unknown) 0x80 10 none
[admin@MikroTik] >

Can anyone provide advice to why this script doesnt work?