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";
}