Community discussions

MikroTik App
 
MarcusH
just joined
Topic Author
Posts: 14
Joined: Thu Aug 02, 2012 11:06 am

Suppress output from ping in script?

Wed Jul 30, 2014 7:02 pm

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Suppress output from ping in script?

Wed Jul 30, 2014 10:58 pm

Is there a way to suppress the output from the ping command in a script?
Not.
I'm Italian, not English. Sorry for my imperfect grammar.
 
harrysuccess
just joined
Posts: 8
Joined: Mon Oct 04, 2010 5:23 am

Re: Suppress output from ping in script?

Mon Nov 06, 2017 3:39 am

use execute {command}
if ([execute {ping 8.8.8.8 count=3}]!= 0) do={put "ok"}
 
dmitris
Frequent Visitor
Frequent Visitor
Posts: 91
Joined: Mon Oct 09, 2017 1:08 pm

Re: Suppress output from ping in script?

Thu Feb 28, 2019 11:09 am

use execute {command}
if ([execute {ping 8.8.8.8 count=3}]!= 0) do={put "ok"}

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
Image
 
ericomattos
just joined
Posts: 1
Joined: Wed Dec 04, 2019 12:21 pm

Re: Suppress output from ping in script?

Wed Dec 04, 2019 12:38 pm

use execute {command}
if ([execute {ping 8.8.8.8 count=3}]!= 0) do={put "ok"}

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:

Code: Select all

# 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

Who is online

Users browsing this forum: Mlodys and 18 guests