Community discussions

MikroTik App
 
akliouev
just joined
Topic Author
Posts: 19
Joined: Wed Dec 25, 2013 9:24 am

Variable substitution in "on-up" scripts

Sun May 26, 2024 9:58 am

Greetings,

I've bumped into a very strange behaviour on a ROS 7.14.3 system yesterday and I wonder if this is by design or a bug:

I have a script in /system/scritps called "telegramSend" that sends the content of a variable "message" to the preconfigured chat with a preconfigured bot token

I wanted the router to send messages when a VPN connection is established and made the following script in the "on-up" section of the PPP profile:
{
:local remad $"caller-id";
[[:parse [/system script get telegramSend source]] message="Admin VPN login $user from $remad"]
}


This failed miserably. I've spent several hours trying to figure out what was wrong with this and it turned out that the variable substitution in the same line as function execution was preventing the script to complete. So the following modification fixed the problem:
{
:local remad $"caller-id";
:local msg "Admin VPN login $user from $remad"
[[:parse [/system script get telegramSend source]] message=$msg]
}
Is this behaviour normal for "on-up" "on-down" scripts? My telegramSend script uses a similar variable substitution and seems to be working just fine after being invoked from the "on-up" script:
...
/tool fetch url="https://api.telegram.org/bot$botToken/sendmessage\?chat_id=$chatID&text=$message" keep-result=no
...
Update: the same behaviour is on a ROS 6.49.10....