Community discussions

 
baumie
newbie
Topic Author
Posts: 39
Joined: Mon Mar 19, 2007 7:51 pm
Location: South Africa

parameters for scripting

Sat Apr 05, 2008 2:22 pm

Hi
I want to know if there's a way of passing parameters to a MT script. For instance I want to change the rate-limits for centain user groups can I write one script and get the limits from parameters passed to the script or must I do a script for each rate limit and group
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5921
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: parameters for scripting

Mon Apr 07, 2008 9:33 am

You can use global variables, for example,

simple script "myScript":
{
:global myVar;
:put &myVar;
}

Before calling "myScript" set "myVar" value:

{
:global myVar 999;
/system script run myScript;
}
 
baumie
newbie
Topic Author
Posts: 39
Joined: Mon Mar 19, 2007 7:51 pm
Location: South Africa

Re: parameters for scripting

Thu Apr 10, 2008 9:38 am

Thanks I never thought of that but it will solve my problem
 
User avatar
Etz
Member Candidate
Member Candidate
Posts: 153
Joined: Thu Mar 27, 2014 10:09 am
Location: Estonia

Re: parameters for scripting

Wed Feb 13, 2019 12:13 am

Sorry for necro posting, but how do you pass multiple parameters to script?

Would this work?:
{
:global myVar1 999;
:global myVar2 9999;
/system script run myScript;
}
Considering that MyScript has global scope variables MyVar1 and MyVar2 present?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1296
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: parameters for scripting

Wed Feb 13, 2019 4:25 pm

Should work as long as you declare your global variables in the sub script like this:
:global myVar1
:global myVar2
PS, you do not need ut use ; at the end of the line, only to separate multiple commands at the same line.
So your script could be written:
{
:global myVar1 999
:global myVar2 9999
/system script run myScript
}
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
A9691
just joined
Posts: 13
Joined: Sat May 14, 2016 10:58 am

Re: parameters for scripting

Thu Sep 12, 2019 4:24 pm

You can pass parameters to script files run with /import. For example:
Content of fact.rsc:
:if ($1 > 1) do={
	:global fact
	:set $result ([$fact ( $1 - 1 )]*($1))
} else={
	:set $result 1
}
Define fact function:
:global fact do={/import "fact.rsc"; return $result}

Testing:
[admin@bkeniko] > :put [$fact 3]

Script file loaded and executed successfully

Script file loaded and executed successfully

Script file loaded and executed successfully
6
[admin@bkeniko] > 

Is there any documentation on this?
(tested on v6.40.8 )
 
User avatar
SiB
Member Candidate
Member Candidate
Posts: 148
Joined: Sun Jan 06, 2013 11:19 pm
Location: Poland

Re: parameters for scripting

Fri Sep 13, 2019 12:40 pm

Is there any documentation on this? (tested on v6.40.8 )
.
I think it's new, I cannot see about passing variable by global function.to /import feature. This is like recursion . Works in 6.45.3
MTCNA + MTCRE + MTCINE | ~600 users at ~150 RouterBoards in EMEA | Telegram: @SiB_PL | WebChat: Tokonda

Who is online

Users browsing this forum: No registered users and 5 guests