API to Create/Set Scripts?

Is it possible to utilize the API to

  1. Create a Script on RB IFF it doesn’t exist.
  2. Set the Source of that Script



    I was looking at the PERL Library to do this via the API, but whenever I touch /system/script anything… it just seems to never return.

Anyone have any advice?

-Eric

there should be no problems creating a script and even run it via API.

Maybe you need to explicitly ask for the response? That is, if the client doesn’t do that automatically, the actual add/set may not complete until you do.

“/system/script/add”, as well as “/system/script/set” both work on my RouterOS (6.2). I’m using my client, but I see no reason the Perl client would be any different.

Besides, have you tried doing the same on other menus? Does it work at least there?

Using the perl API for right this second, but basically what is happening is when I ask for the source it doesn’t seem to return from the function.

Does “/system/script/print” work via the API for you? That is what is hanging… anytime I request the source it seems to hang. My guess would be that the library isn’t handling newlines or something like that. But just verifying it works before I try to figure out what is wrong with the library.

what command exactly you are trying to use?

you have to treat script entried like simple items, like ip address. you cannot have anything interactive in API.

After a brief debug it looks like

a) either the API is returning “!do” after the end of the source… or
b) the library isn’t detecting the end of the stream because it is looking for “!done” but only sees “!do”.

Not sure why yet…

PERL API from the other thread.

Trying to use something like this
my(%scripts) = Mtik::get_by_key('/system/script/print,‘name’);

To get a list of all of the scripts and their contents… The problem is library is hanging on the request. Trying to debug it, but it seems like it isn’t getting the full final line… so it only sees “!do” instead of “!done” and thus just keeps trying to read from the socket.

in the other thread i already replied, this looks implementation specific. I used Python example, as it allows write commands on the fly and see the result as it is sent from the router.

/system/script/print
=.proplist=.id,name,source

<<< /system/script/print
<<< =.proplist=.id,name,source
<<< 
>>> !re
>>> =.id=*1
>>> =name=script1
>>> =source=asdfasdfasdfsadf
>>> 
>>> !done
>>>

maybe it reads length incorrectly, as result you do not get correct responses in the end.

you can try to set .proplist items in a different order to see weather other items get wrong length too.

Just saw your reply. Thanks… Yep… the bug is in the line length somewhere. I’ll poke at it later.

Thanks for the clarification and the tip re: python. Maybe I’ll use python for this instead of debugging the library.