Is there a way to suppress the output from the ping command in a script? I am on 6.x - running 6.15
Essentially, I only want the return value from the command - number of successful pings - without the ping command printing to the console.
:local addr 192.168.100.2
:local pingInt "50ms"
:local pingCount 5
:if ([/ping address=$addr interval=$pingInt count=$pingCount] = 0) do={
:put ("Ping: FAILED")
} else={
:put ("Ping: OK")
}
Right now this produces:
/system script run test
HOST SIZE TTL TIME STATUS
192.168.100.2 56 64 0ms
192.168.100.2 56 64 0ms
192.168.100.2 56 64 0ms
192.168.100.2 56 64 0ms
192.168.100.2 56 64 0ms
sent=5 received=5 packet-loss=0% min-rtt=0ms avg-rtt=0ms max-rtt=0ms
HOST SIZE TTL TIME STATUS
Ping: OK
What I want is this:
/system script run test
Ping: OK
Actually, there seems to be a bug in the output of ping - does not switch off bold face. My put command prints in bold face.
use execute {command}
if ([execute {ping 8.8.8.8 count=3}]!= 0) do={put “ok”}
dmitris
4
Hi There, seems this solution not working as expected. Does anybody solve this task in other manner ?
[admin@mtik] > :put [:execute {/ping 192.168.88.1 count=5}]
Output:
*d3
Hello,
The “:execute” command returns the job id, so that code will always return “ok”.
One alternative is:
Create a temp global variable
:global ABC “”
Execute the ping in background and get the jobId
:local jobId [:execute {:global ABC [:ping count=5 192.168.88.1]}]
Waits the job end
:while ([:len [:system script job find .id=$jobId]] > 0) do={
:delay 1s;
}
Use the result on the global variable
:put $ABC
search tag # rextended execute
Bravo!
:global pingResult -1
{
:local jobID [:execute ":set pingResult [:ping count=5 1.1.1.1]"]
:while ([:len [/system script job find where .id=$jobID]] > 0) do={
:delay 1s
}
}
:put $pingResult