fetch seems to behave different when called in function
Posted: Thu Feb 29, 2024 3:07 pm
I'm trying to get my feet wet with MikroTik scripts. After having a basic script I'm trying to clean it up a bit and wrap certain parts into functions.
When doing this with the fetch function it seems to behave different:
The part runs without issues but when $updateDDNS is called there is an error "failure: Mode not specified", if the mode gets specified the next error appears ("failure: Please provide IP address or host") and so on...
When the variable $afraidSyncURL gets replaced by the actual value within $updateDDNS the script works, but its not clear exactly why.
Why do the two calls behave differently?
When doing this with the fetch function it seems to behave different:
Code: Select all
# MikroTik script to update the DNS entry when Internet connection has been
# established via PPP.
#
# Put this into the PPP profile as script on-up and assign the profile to the
# pppoe connection.
#
# Permissions required:
# - read
# - test
#
:global afraidSyncURL "http://sync.afraid.org/u/random_token/";
:local updateDDNS do={
:local result [/tool fetch url=$afraidSyncURL as-value output=user]
:if ($result->"status" = "finished") do={
:log info ("FreeDNS: " . $result->"data");
}
}
:log info "FreeDNS: IP address update started";
:local result [/tool fetch url=$afraidSyncURL as-value output=user]
:if ($result->"status" = "finished") do={
:log info ("FreeDNS: " . $result->"data");
}
$updateDDNS
:log info "FreeDNS: Update script finished"
Code: Select all
:local result [/tool fetch url=$afraidSyncURL as-value output=user]
:if ($result->"status" = "finished") do={
:log info ("FreeDNS: " . $result->"data");
}
When the variable $afraidSyncURL gets replaced by the actual value within $updateDDNS the script works, but its not clear exactly why.
Why do the two calls behave differently?