Community discussions

MikroTik App
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

passing variable to script

Thu Oct 08, 2015 2:54 pm

how can i pass my dynamic variable from command to script?
example:
/sys script run MYSCRIPT MYVARIABLE
(MYVARIABLE can be dynamic like user1 or user2 etc)
 
dada
Member Candidate
Member Candidate
Posts: 245
Joined: Tue Feb 21, 2006 1:44 pm

Re: passing variable to script

Thu Oct 08, 2015 4:58 pm

IMHO the only way is to use global variables

http://forum.mikrotik.com/viewtopic.php?f=9&t=23041
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

Re: passing variable to script

Thu Oct 08, 2015 6:08 pm

IMHO the only way is to use global variables
http://forum.mikrotik.com/viewtopic.php?f=9&t=23041
Thank you for your reply. I already read that before posting, but its not a neat solution. I wanted to pass simple variable like we do in bash.
Example:
/sys scr run Myscript username1
/sys scr run Myscript username2
and so on to query some customized info using same script to pull specific users info.
Y its so hard to add this simple task in the MT Scripting :?
 
User avatar
PaulsMT
MikroTik Support
MikroTik Support
Posts: 282
Joined: Tue Feb 10, 2015 3:21 pm

Re: passing variable to script

Thu Oct 08, 2015 7:34 pm

Create global variable with some value (username1)

:global variable username1

Use $variable in your script. When you need, simply change the value of specified variable:

:global variable username2

This way you will be able to run same script, by only changing one variable.
 
efaden
Forum Guru
Forum Guru
Posts: 1708
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: passing variable to script

Thu Oct 08, 2015 8:32 pm

You can also use functions.
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

Re: passing variable to script

Fri Oct 09, 2015 8:45 am

Create global variable with some value (username1)
:global variable username1
Use $variable in your script. When you need, simply change the value of specified variable:
:global variable username2
This way you will be able to run same script, by only changing one variable.
Ok I got it. Every time i have to change the global variable first, then run the script. two steps burden :)

All of you, Thank you for your support and suggestions

Who is online

Users browsing this forum: No registered users and 8 guests