Hi
I’m trying to connect from one router to another to get wifi signal-strength
:global GoldenUser; :global GoldenIP
:local myMac E4:8D:8C:26:DC:03
do {
:local out [[ /system ssh user=$GoldenUser $GoldenIP ":put [/interface wireless registration-table get [ find mac-address=$myMac ] signal-strength ]" ]]
:put "out:$out:"
} on-error={
:put "ERR"
}
but when I run the script it seems that the remote command is run but, it does not generate an error, but its output is not captured.
looks like /system ssh sends the remote command output to stderr instead of stdout, so it is printed to console but not captured by the script
/system script> run test
-78dBm@6Mbps
Welcome back!
out::
any hints?
thanks
MAtteo
Sinan
January 4, 2017, 8:52pm
2
Try to put the result in a file then get it by fetch tool
not sure if there is a feature to redirect the output to a file (afterall, routeros is Linux-based).
can you try this..
/system script> run test file=someoutput.txt
and see if that is what you need?
parameter is not supported:
[toor@PEAMI-GW] /system script> run test file=someoutput.txt
expected end of command (line 1 column 10)
version: 6.36.4 (bugfix)
SSH command output can be saved with “output-to-file” option.
Any other script/command output you can save with :execute command:
For example - save output of your script:
The script:
/system script add name=ScriptExample source={
/system clock print
}
Execute script, and save output:
{:local a [/system script get ScriptExample source]; execute script=$a file=OutputOfScript}
Or simply save output of any command:
:execute script={/system clock print} file=OutputOfCommand
true, thanks (meanwhile I had found it out too)
but there is another quirk: the file content is not immediately available, you need to insert a delay between creating the file and reading it (sic):
:global GoldenUser; :global GoldenIP;
:local filename outfile
:local myMac E4:8D:8C:26:DC:03
#:local myMac 04:F0:21:1D:77:70
do {
/file remove out
} on-error={
:put "file already deleted"
}
do {
/system ssh user=$GoldenUser $GoldenIP ":put [/interface wireless registration-table get [ find mac-address=$myMac ] signal-strength ]" output-to-file=$filename
} on-error={
:put "ERR"
}
:delay 1
:local result
:set result [ /file get [ find name=$filename ] contents ]
:put "res:$result:$filename"
(without :delay the script fails!)
this script runs fine from the console, but not if launched remotely via SSH:
from console:
[root@router] /system script> run test
file already deleted
Welcome back!
res:-85dBm@6Mbps
:outfile
launching from SSH, the outbound ssh connection seems to fail (out file is not created)
$ ssh root@ROUTER_IP "/system script run test"
root@ROUTER_IP's password:
file already deleted
ERR
res:-85dBm@6Mbps
:outfile
any hint on why this happens/how to fix it?
also if I run the script trough :execute it fails to connect via ssh
[root@router] /system script> {:local a [/system script get test source]; :execute script=$a file=OutputOfScript}
[root@router] /system script> :put [ /file get OutputOfScript.txt contents ]
file already deleted
ERR
no such item
it seems that there is something really hard about using outbound SSH in a script, or possibly this could be the result of some security measure