Script runs from terminal but doesn't run from scheduler

I have a RB751G-2HnD running RouterOS 5.25
I have found that the following script will run OK when launched from the console, but not from webfig, winvox or scheduler:

:global IPSECOLD
:local IPSECNEW [:resolve xyz.dyndns.org]
:if ($IPSECNEW != $IPSECOLD) do={
:set IPSECOLD $IPSECNEW
/ip ipsec policy set 1 sa-dst-address=$IPSECNEW
/ip ipsec peer set 1 address=“$IPSECNEW/32”
:log info “IPSec: remote peer updated”
} else={
:log info “IPSec: no update needed”
}

The specific command that won’t execute when script is run from either, webfig, winbox or scheduler is:
/ip ipsec peer set 1 address=“$IPSECNEW/32”

If the condition is met, the log only shows “ipsec policy changed by admin” and nothing else when run from webfig, winbox or scheduler, while if run from terminal, all the actions are executed and get logged: “ipsec policy changed by admin”, “ipsec peer changed by admin”, “IPSec: remote peer updated”

Could this be a bug on 5.25? I’m pretty sure that this was working correctly on 5.23

Did you ever figure this out.
Different script but same symptoms.
Runs fine if I execute it from terminal, but not from Winbox or Netawatch

this is all that is in the script
/ip route set [find comment=WAN1] distance=10
/ip route set [find comment=WAN2] distance=20

ROS 6.6 - but tried some older versions with same result

Try:

/ip route set [/ip route find comment=WAN1] distance=10
/ip route set [/ip route find comment=WAN2] distance=20

There are different set of variable scopes for each mode of script startup. Until it is not fixed or improved, it is better to reduce any use of global variables. The ROS scripting is a terrible beast - simple script will beg the CPU too much for my likings. I hope for a JIT compiler to get implemented.