Correction to Interface Monitoring Script... Unable to resolve

Hi,
I’m new to Mikrotik. I found a few scripts and modified them slightly, but started getting an error, here is the script:

Script#1
:if ([/interface l2tp-client get VPN connected]=true) do={} 
else={
/log warning "VPN NOT connected"; 
/interface l2tp-client disable VPN;
/delay 15; 
/interface l2tp-client enable VPN;};

Script#2
:if ([/interface dhcp-client get WAN bound]=true) do={} 
else={
/log warning "WAN NOT connected"; 
/interface set [find name=WAN] disabled=yes;
/delay 1; 
/interface set [find name=WAN] disabled=no};

In Scripts#1, when i run it, it says: “input does not match any value of value-name” and the same for Script#2. Those two statuses by far is what i want to monitor, is there a better way around it, or better alternative. I’m not very sophisticated in running scripts, I’m still learning… Am I missing something?

No idea where you have found them and how old they are, but in current RouterOS:

  • for l2tp-client, the property you need to test is running, not connected
  • for dhcp-client, the property you need to test is state, not bound, and the values are not true | false but bound | error | rebinding… | requesting… | searching… | stopped

Other than that, i’d recommend you to invert the condition, put the interface restart part script to do={} , and leave out else={} completely.

Script#1
:if ([/interface l2tp-client get VPN running]=false) do={
  /log warning "VPN NOT connected"; 
  /interface l2tp-client disable VPN;
  /delay 15; 
  /interface l2tp-client enable VPN;
};

Script#2
:if (!([/ip dhcp-client get [find interface=WAN] status]~"bound")) do={
  /log warning "WAN NOT connected"; 
  /interface set [find name=WAN] disabled=yes;
  /delay 1; 
  /interface set [find name=WAN] disabled=no
};

Hi.Thanks. I found on forum that sometimes “running” can be deceiving when the link on interface tries to connect it shows running but not connected. Thats why i was thinking on monitoring just connected. Am I wrong?

I think the error is related as it says to the value-name which happens to be your input so edit the script and change the name of the l2tp-client to the actual name of your l2tp-client or rename the interface to match the #script1.

Same for script 2 check that your interface is named WAN if not rename script with correct interface name or rename interface. Also apply what @sindy said or you won’t know the status even if looking at the correct interface.

Unfortunately, the connected field is not available in 6.42. Given what error you got, I’m afraid it is not available in the version you run either. I’m not sure whether it is because running is now set to true only if the connection has succeeded (so no need for a separate connected field) or whether Mikrotik just neglects that aspect.