Community discussions

MikroTik App
 
jonathan2493
newbie
Topic Author
Posts: 25
Joined: Fri Feb 13, 2015 4:25 am

Netwatch Script Question

Fri Feb 03, 2017 5:34 am

hi ,

I just currently using one of the scripts for failover.

i just want to understand some part of the script.
/system script add name=pinging source={
  :if ([/ping 1.1.1.1 count=5] = 0) do={
    /tool e-mail send \
      to=example@example.com \
      subject="Can't ping 1.1.1.1"
    }
  }

The 2nd line
 :if ([/ping 1.1.1.1 count=5] = 0) do={
What does the code actually do?
Is 0 the number of replies that is needed for the condition to be successful or is it sort of an exit status?
 
Reg24
just joined
Posts: 3
Joined: Fri Feb 03, 2017 3:45 am

Re: Netwatch Script Question

Fri Feb 03, 2017 7:28 am

Some console commands are most useful if their output can be used as an argument value in other commands. In console, this is done by "returning" value from commands. Return value is not displayed on the screen. When you type such a command between square brackets '[' ']', this command is executed and it's return value is used as the value of these brackets. This is called command substitution.
https://www.mikrotik.com/documentation/ ... pting.html
I don't know, why I cannot find this info in more recent source.
 
jonathan2493
newbie
Topic Author
Posts: 25
Joined: Fri Feb 13, 2015 4:25 am

Re: Netwatch Script Question

Fri Feb 03, 2017 10:13 am

Thanks for reply and the link.

Ive tested the output of

:put [/ping 8.8.8.8 count=15];

Ive created a firewall rule on the router to block inbound traffic if the source is 8.8.8.8. Ill be re-enabling and disabling the firewall rule to control the count of successful pings.

There is a number on the end of ping test. Its the count of the successful pings.
You do not have the required permissions to view the files attached to this post.