Community discussions

 
upnort
newbie
Topic Author
Posts: 45
Joined: Wed Aug 15, 2018 2:03 am

Scripting output

Tue Aug 20, 2019 10:30 pm

My understanding is script output cannot be viewed directly. Instead the output needs to be sent to the log.

I created a simple script, test.rsc:

:local myVar;
:set myVar "test";
:log info "$myVar";


I uploaded the script with scp. I added the script to the script "repository":

/system script add name=test.rsc policy=read,write

Running /system script print shows no errors and lists the script.

When I run the script there are no error messages and there is nothing in the log.

I can manually type :log info "This is a test" and the text appears in the log.

1. What am I doing incorrectly?

2. Do scripts have to use Windows (CR/LF) line endings?

3. When I type /log print I see two entries because I have disk logging configured. How do I show only memory or disk entries?

Thank you. :)
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1296
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Scripting output

Tue Aug 20, 2019 11:14 pm

Change :log info to :put and you get output on your console and wrap the code in {} and you can run int from command line to test thing out.

So this works fine:
{
:local myVar
:set myVar "test"
:put "$myVar"
}
PS ; is not needed, only when multiple commands on same line

You can also skip the set (depending on your code) and do like this:
{
:local myVar "test"
:put "$myVar"
}
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
upnort
newbie
Topic Author
Posts: 45
Joined: Wed Aug 15, 2018 2:03 am

Re: Scripting output

Tue Aug 20, 2019 11:33 pm

Thank you for replying. I'm still not getting any output. :(

I think the problem might be the script. When I run /system script print the script is tagged as I - Invalid. I'm looking around the web for how to remedy the problem but am not finding clues.

Edit: I found the problem. Puzzled how to fix.

Seems I am uploading the file correctly and setting permissions correctly.

The file appears in /file print.

I run /import test.rsc command and see output of Script file loaded and executed successfully

Next I run /system script edit test.rsc source and there is nothing in the script. I copy and paste the contents and then all is well.

Something seems awry with the way I am creating the script and possibly with how I am uploading and importing.
 
upnort
newbie
Topic Author
Posts: 45
Joined: Wed Aug 15, 2018 2:03 am

Re: Scripting output

Wed Aug 21, 2019 12:27 am

Apparently I misunderstood the /import command. The command has nothing to do with preparing the script. The command is for appending the current configuration.

Who is online

Users browsing this forum: No registered users and 6 guests