Dynamic DNS Script for custom solution

Hi would you kindly take a look at this script an tell if there es anything wrong with it or if it can be optimized somehow.

Thank you.

set mandatory variables

:local username [/system identity get name ]
:local password "test"

:global dyndnsForce
:global previousIP

:log info ("previous IP is $previousIP")

get currentIP to file currentip.txt

/tool fetch mode=http url="http://ddns.xxxxxx.xxx/nic/checkip" dst-path=/currentip.txt

parse file currentip.txt for current IP

:local currentIP [/file get currentip.txt contents]

:set dyndnsForce true

Update dynlan1.de

The following checks first whether or not the currentIP matches the previousIP and based on that information either in case they don't match updates $username.xxxxxx.xxx with the currentIP or in case they do match logs that no update was needed

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={

:set dyndnsForce true
:set previousIP $currentIP
/tool fetch mode=http url="http://$username:$password@ddns.xxxxxx.xxx/nic/update?hostname=$username&myip=$currentIP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG" dst-path=/dyn.txt
:set previousIP $currentIP
:log info ("Updated $username.xxxxxx.xxx to $currentIP")
:log info ("current IP is $currentIP")
} else={
:log info ("$currentIP = $previousIP No update needed!")
}

Using this script I encountered that when run on a router that should tunnel all traffic through vpn, ist ist not chekcing throught the vpn but rather throught the actual internet connection.
Does anybody have an idea how that coul be mitigated?

Thank you.

Best regards

1001001

nevermind, fixed it by adding a nwe route for the request.