Community discussions

MikroTik App
 
spyghost
newbie
Topic Author
Posts: 27
Joined: Mon Feb 27, 2023 9:55 am

One-liner with global var over ssh vs on ROS terminal

Sat Apr 29, 2023 5:07 pm

I got a script that aims to accept variable arguments when invoked - I believe the only way to do this is via globals (cmiiw).
{
    :global networkName
    :global download
    :global upload

    :local setQueueTreeMaxLimit do={
        :local currentMaxLimit [/queue/tree/get [find name=$queueTreeName] max-limit]
        :put $currentMaxLimit
    }

    $setQueueTreeMaxLimit queueTreeName=($networkName . "-download") maxLimit=$download
    $setQueueTreeMaxLimit queueTreeName=($networkName . "-upload") maxLimit=$upload
}
When invoked from terminal, it works...
> :global networkName Guest; :global download 5000000; :global upload 5000000; /system/script/run set-queue-max-limit
Guest-download
5000000
Guest-upload
5000000
But from an ssh session, it complains about 'no such item'
$ ssh user@device ":global networkName Guest; :global download 10000000; :global upload 10000000; /system/script/run set-queue-max-limit"
Guest-download
no such item
I'm pretty sure the offending line is this,
:local currentMaxLimit [/queue/tree/get [find name=$queueTreeName] max-limit]
.

But what I cannot understand is that why this line borks over ssh, but in in termal.... Any thoughts as to why?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: One-liner with global var over ssh vs on ROS terminal

Sun Apr 30, 2023 12:45 am

Where is the command that write "Guest-download" on terminal???

I do not understand at all what your script try to do...
 
spyghost
newbie
Topic Author
Posts: 27
Joined: Mon Feb 27, 2023 9:55 am

Re: One-liner with global var over ssh vs on ROS terminal

Sun Apr 30, 2023 2:12 am

This particular routine, which is just part of a larger is script was isolated for the error I found from ssh.

This specific routine accepts a parameter of Guest and uses it to get the max-limit of queue tree names Guest-download and Guest-upload.

The 2nd code block is ran directly from the winbox terminal. The 3rd code block from an ssh session.

If you compare both outputs, winbox terminal runs as expected, but the one from ssh errs at the queue tree line, which I don't grasp why in spite of being exactly the same.

What makes these two different?
$ ssh user@device ":put [/queue/tree/get [find name="Guest-download"] max-limit]"
no such item
vs inside the mikrotik device
[user@device] > :put [/queue/tree/get [find name="Guest-download"] max-limit]
5000000
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: One-liner with global var over ssh vs on ROS terminal

Sun Apr 30, 2023 8:43 pm

What you obtain by ssh with

ssh code

user@device ":put [/queue/tree get [find where name=Guest-download] max-limit]"
?
 
spyghost
newbie
Topic Author
Posts: 27
Joined: Mon Feb 27, 2023 9:55 am

Re: One-liner with global var over ssh vs on ROS terminal

Mon May 01, 2023 9:05 am

Seems I've solved my own problem... apparently this particular routine requires a 'read' privilege which I didn't tick. All working now after ticking the 'read' permission.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: One-liner with global var over ssh vs on ROS terminal

Mon May 01, 2023 9:31 am

...this particular routine requires a 'read' privilege...
Noooo... Seriously?

I thought that you needed "dude" permission to read,
and that in the examples if one writes "$ ssh user@device" and "[user@device] >" it means the same user, but look what I thought...

Who is online

Users browsing this forum: No registered users and 13 guests