First script problem - just won't execute
Posted: Fri Nov 29, 2024 11:22 pm
I'm writing my first script (from examples found online). The first line SHOULD show a message in the system log, but it does not (when I manually start the script from the /SYSTEM/SCRIPTS window. What is wrong?
I'm not sure how the mikrotik script interpreter works, but will it execute lines UNTIL it finds a syntax error? Or will even a single error in the script cause it to not execute?
Code: Select all
{
:log info "DHCP client being executed for backup internet link"
# Find route by matching comment, and count number of times route exists
:local count [/ip route print count-only where comment="HOST-ON-WAN-BACKUP"]
# If just got an IP address
:if ($bound=1) do={
# If no such route, just add a new one
:if ($count = 0) do={
/ip route add gateway=$"gateway-address" comment="HOST-ON-WAN-BACKUP"
}
# Else at least one such route exists
else={
# If found exactly one match, update it
:if ($count = 1) do={
:local test [/ip route find where comment="HOST-ON-WAN-BACKUP"]
:if ([/ip route get $test gateway] != $"gateway-address") do={
/ip route set $test gateway=$"gateway-address"
}
# Else multiple routes found, unable to update
} else={
:log error "DHCP Client Script: Multiple routes found for HOST-ON-WAN-BACKUP"
}
}
}
# Else just lost the IP address
else={
/ip route remove [find comment="HOST-ON-WAN-BACKUP"]
}
}