Basic Scripting - Retrieving variables from remote RB

Hi,

Trying to set a script for one Mikrotik to get data from another.
E.g, I want to catch the current TX-CCQ on one “tik” by running a script on another.

I’ve come up with

/sys ssh 10.1.10.119 user=test ":put [/interface wireless registration-table get 0 tx-ccq]"

This will generate an output similar to:

73

Welcome back!

Obviously, it’s printing the CCQ in the ssh-session, and then disconnects.
What I’m trying to do is get that “73” into a variable on the routerboard running the script. Is that at all possible? How?

Well, this may not be the most elegant, but it works.

The local router connects via ssh and tells the remote router to save the tx-ccq value to a file. Then, the local router connects via ftp to the remote router, downloads the file and saves the contents as a variable. The only non-automated part is that you have to type in the ssh password. I couldn’t find a way to do this automatically.

You’ll have to change a few details (IP address, ftp password).

{
# Script to get get data from a remote MikroTik
# Tested on RouterOS v5.7

# set remote MikroTik IP address
:local ip 10.46.96.11;

# set filename to use for remote data
:local myData "data.txt";

# on the local MikroTik, check to see if file exists, if so, delete
if ([ :len [/file find name=$myData]] = 1) do={
	/file remove $myData;
}

# ssh to remote IP, create new file containing the tx-ccq value
/sys ssh $ip user=admin "/file print file=$myData;:delay 2s;/file set $myData contents=\"$[/interface wireless registration-table get 0 tx-ccq]\"";

# while the file does not exist locally, request it via ftp
# without this loop, it the rest of the script is executed before the file is finished transferring
while ([ :len [/file find name=$myData]] < 1) do={
	/tool fetch address=$ip src-path=$myData user=admin mode=ftp password=MYPASSWORD dst-path=$myData port=21;
} 

# get the contents of the local file
:local content [/file get [/file find name=$myData] contents] ;
# show remote IP and info
:put "($ip) Remote tx-ccq: $content";
}

It is possible to automate ssh login:
http://wiki.mikrotik.com/wiki/Use_SSH_to_execute_commands_(DSA_key_login)

  1. Generate public & private key

  2. Import public key to remote RB

  3. Import private & public keys to local RB

  4. Execute remote commands without having to enter password

Is there any “online” way how to call a script remotely and get its output into local variable? I mean something like RFC (remote function call).

I know that Dude can get result of any ROS command of selected device, but I need to get result of command into other ROS device.

At least, can I read OID by script from other device via SNMP?