Note sure what info you’re after but it’s better to put the work in once on the Mikrotik to properly format output that’s easily parseable on your linux system.
i.e. this produces an array of json objects.
local result "["
#as-value produces an array of dictionary-style key/value pairs for each line normally printed
foreach item in=[ip hotspot user print as-value where name=60:8F:5C:B8:75:4F] do={
local thisItem "{"
#this loop runs through the key/value pairs for each item in the array
foreach key,value in=$item do={
#concatenate previous $thisItem value + key + : + value
set thisItem ($thisItem."\"".$key."\":\"".$value."\"},")
}
set result ($result.$thisItem)
}
#strip trailing , from result
set result [pick $result 0 ([len $result]-1)]
#close the open bracket
set result ($result."]")
#dont print result if it's not populated
if ([len $result]>2) do={
put $result
}
You can then pipe this into jq to get what you want. Say,
| jq '.[]|select(."mac-address"=="60:8F:5C:B8:75:4F")|.uptime'
You can also add above script as a function on the Mikrotik so you don’t need to call the whole thing each time via SSH.
global getUsers do={
local result "["
foreach item in=[ip hotspot user print as-value where name="$1"] do={
local thisItem "{"
foreach key,value in=$item do={
set thisItem ($thisItem."\"".$key."\":\"".$value."\"},")
}
set result ($result.$thisItem)
}
set result [pick $result 0 ([len $result]-1)]
set result ($result."]")
if ([len $result]>2) do={
put $result
}
}
You would then run ‘$getUser “60:8F:5C:B8:75:4F”’ via SSH.
Of course the function will be lost on reboot, so you need a scheduler to load it on startup.