Community discussions

MikroTik App
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

where can I create a script in RouterOS?

Thu Sep 23, 2010 12:05 am

Hello to all,

I am very new at scripting, I've been reading scripting examples and scripting manuals at the wiki
http://wiki.mikrotik.com/wiki/Manual:Scripting

and I can understand those pretty well...but i have no idea where to create the scirpt, and is that I open a new terminal and start
[admin@MKTStation] >:global currentIP;
[admin@MKTStation] >:local newIP [/ip address get [find interface="ether1"] address];
[admin@MKTStation] >:if ($newIP != $currentIP) do={
syntax error (line 1 column 7)
Can you understand what i mean?? :?: :?: ...is that I don´t know where to put the script...hopefully I am explaining myself right, can I put it in a notepad and then upload it into files or what? and if it does..what is the extension? .rsc? .txt?

Thanks a lot for your help and support

Regards
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: where can I create a script in RouterOS?

Thu Sep 23, 2010 12:22 am

/system script
You can add a script there:
/system script add name=test
And use the built in editor to edit the source:
/system script edit [/system script find name=test] source
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

Re: where can I create a script in RouterOS?

Thu Sep 23, 2010 12:27 am

Thanks a lot fewi...you always help me really quick!!
 
madmoses
just joined
Posts: 18
Joined: Mon Sep 26, 2016 6:19 pm

Re: where can I create a script in RouterOS?

Sat Aug 24, 2019 2:49 pm

Is it also possible to create and view scripts in the web gui?
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: where can I create a script in RouterOS?

Sat Aug 24, 2019 6:59 pm

Yes, same like in Winbox, you have two possibilities - to click the [Terminal] button to get a command line window, or to go System -> Scripts and edit just the script body itself in the form. But if the script has to output something, run it from the command line window.
 
User avatar
boldsuck
Frequent Visitor
Frequent Visitor
Posts: 60
Joined: Sun Sep 01, 2013 1:07 am
Location: Germany

Re: where can I create a script in RouterOS?

Sat Aug 24, 2019 11:43 pm

After adding your script, you want to do it automatically. ;-)

please refer:
/system scheduler
(= GNU/Linux cronjobs)
 
larsac
just joined
Posts: 22
Joined: Thu Apr 30, 2020 4:52 pm

Re: where can I create a script in RouterOS?

Fri Jun 19, 2020 12:02 am

Could I also create a script from within an .rsc file ? Or can I ftp the script contents as a file and turn them into a script from command line ?

I would like to version control my config and script outside of RouterOS, that's why I'm asking.

Lars
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: where can I create a script in RouterOS?

Fri Jun 19, 2020 12:22 am

Sure, everything is possible... Run
/ system script export;
to see what the code inside an rsc file should look.

To turn an uploaded file into a script:
/ system script add name=new-script source=[ /file get uploaded-script-file contents ];
You may want to take a look at my signature for an idea what's possible. :D
 
larsac
just joined
Posts: 22
Joined: Thu Apr 30, 2020 4:52 pm

Re: where can I create a script in RouterOS?

Fri Jun 19, 2020 12:29 am

Great, Danke !

Lars
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19371
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: where can I create a script in RouterOS?

Fri Jun 19, 2020 2:35 am

You can create a script in a house,
You can create a script with a mouse
You can create a script with the help of fewi
You can create a script with the webgui
You can create a script with green eggs and ham!!
 
msatter
Forum Guru
Forum Guru
Posts: 2912
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: where can I create a script in RouterOS?

Fri Jun 19, 2020 10:45 am

You can create a script in a house,
You can create a script with a mouse
You can create a script with the help of fewi
You can create a script with the webgui
You can create a script with green eggs and ham!!
I don't like the looks of green eggs and if, then I would hide it under the ham.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: where can I create a script in RouterOS?

Fri Jun 19, 2020 11:12 am

I do see many struggle to get script to work on the terminal.

Example if you cut and past this to terminal, you do not get anything out. But will work fine as a saved script.
:local test "My script"
:put $test
To get it to work in the terminal wrap it in brackets {}
{
:local test "My script"
:put $test
}
This will then output "My script"

Who is online

Users browsing this forum: MauriceW and 115 guests