HELPPP ! PING Script

(sorry for my bad english)

Please anybody help me.

I want to make script which PING to YAHOO once each 1 minute.

If PING to YAHOO timeout more than 10 times, will do:
/ip address set [find address=“1.1.1.1/30”] disabled=yes
/tool netwatch set [find host=“1.1.1.6”] disabled=yes
/ip address set [find comment=“1”] disabled=yes
/ip address set [find comment=“2”] disabled=yes

Then if PING to YAHOO reply more than 10 times, will do:
/ip address set [find address=“1.1.1.1/30”] disabled=no
/tool netwatch set [find host=“1.1.1.6”] disabled=no

I don’t know about Linux script, so please anyone can help me for making this script.

Thanks

No one can help me ? :frowning:
Please…my boss start to angry to me :frowning: :frowning:

YUJOBIKA -

You did not say what version of ROS you are using 2.9.xx or 3.x Which one?

Basically I think you are looking for something like this:

:if ([/ping YAHOO count=10]>X) do={
{/ip address set [find address=“1.1.1.1/30”] disabled=yes}
{/tool netwatch set [find host=“1.1.1.6”] disabled=yes}
{/ip address set [find comment=“1”] disabled=yes}
{/ip address set [find comment=“2”] disabled=yes}
}

where X = the minimum number of pings you must get back before you start to disable things. You could use also ‘<’ which would mean ‘less than’.

where YAHOO = the IP address you want to ping

The above script runs in ROS ver 3.x - the script is different for ver 2.9.xx

You can check scripts in the terminal mode of MT ROS - " /system script " and then " print " you will see your scripts and any place that ROS says there is an error in the script.

There is a manual - you need to read up on MT ROS.

R/

Dear galaxynet,

Thank you very much for your “very clear” explanation. I will try to set the script you gave me.
Anyway, my ROS is v3.6.

Dear galaxynet,

What is the script to check if ping is “timeout” or “reply” ?
So if “timeout” to YAHOO, then it will run the script. Then if “reply” to YAHOO, it will run the other one.

Thank You

YUJOBIKA -
Go get the MT 3.0 manual - read it.

To answer your question;

IF works like this: :if [condition is TRUE] do={THIS} else={DO THIS IF FALSE}

So if you use this line; " :if ([/ping YAHOO count=10]>8) do= { TRUE } " then IF the number of pings received back (replies) is greater than 8 then the script will excute the TRUE portion. If the number of replies is 8 or less then it would excute the ELSE portion if it exists otherwise the IF statement is done excuting.

ping looks like this; ping IP ADDRESS ttl=10 count=4 (ttl=TTL=time to live or timeout as you call it)

R/

There is absolutely no need to use ping script in this situation. Just use netwatch and set yahoo ip to watch.

mrz -
If you don’t have something to contribute then stay out of the thread - BTW he is asking for a lot more than to just watch an address and if you had bothered to read everything this fellow has posted (here and elsewhere on the forum) you’d know that…

Dear galaxynet,

I did it !!! I finally success make the script !!! :slight_smile: :slight_smile: :slight_smile:
You just saved my life :slight_smile:

I can not do anything for you beside say HUGE THANKS !!
May GOD bless your kindness !

YUJOBIKA -

You are certainly welcome - glad it all worked out for you.


R/

I know that he was asking more than just watch address.
I just pointed out that there is another solution instead of ping script:

/tool netwatch add host=[:resolve www.yahoo.com] down-script="/ip address set [find address=\"1.1.1.1/30\"] disabled=yes;\n/tool netwatch set [find host=\"1.1.1.6\"] disabled=yes\n/ip address set [find comment=\"1\"] disabled=yes;\n/ip address set [find comment=\"2\"] disabled=yes"

This basically will do the same as ping script you wrote.

galaxynet,

I could not found script tutorial for ROS v3.x in http://www.mikrotik.com/testdocs/ros/3.0/
Where is it ?

Because I want to now the string/script if my condition like this:

  • if ping to yahoo AND ping to google is timeout, then script will be execute
  • if ping to yahoo OR ping to google is timeout, then script will be execute

Or maybe you and someone else can help me ?

Thanks

YUJOBIKA -
The ROS 2.9 script manual is pretty accurate…

For your specific issue it would work like this;

:if ((ping yahoo) && (ping google)) do={…} else{…}

:if ((ping yahoo) || (ping google)) do={…} else {…}


[ && = AND ]

[ || = OR ]

Of course you need to make the (ping yahoo) script portion right - you have that working so I did not repeat the whole thing here…

R/

Dear galaxynet “my best teacher” :slight_smile:

Thanks for the info. I’ll try it.

Dear galaxynet,

My script is work now :slight_smile:
But when the script ping to yahoo & google, why they can not ping in the same time ?
The script ping yahoo first then ping google.

Thanks

:if ([/ping YAHOO count=3 size=28]<2) || ([/ping GOOGLE count=3 size=28]<2) do={/tool netwatch set [find host=“1.2.3.4”] disabled=yes} else={/tool netwatch set [find host=“1.2.3.4”] disabled=no}

Should be - and this was in the example…

:if (([/ping YAHOO count=3 size=28]<2) || ([/ping GOOGLE count=3 size=28]<2**))** do={/tool netwatch set [find host=“1.2.3.4”] disabled=yes} else={/tool netwatch set [find host=“1.2.3.4”] disabled=no}

When you use “:if” you have to evaluate the entire condition. :if (( condition ) || (condition)) do={this}

See the double parens " (( " and the closing " )) "

R/

YUJOBIKA -

Because I want to now the string/script if my condition like this:

  • if ping to yahoo AND ping to google is timeout, then script will be execute
  • if ping to yahoo OR ping to google is timeout, then script will be execute

Two scripts would be easier for you to handle one with the AND condition and one with OR.

:if (((([/ping YAHOO count=3 size=28]<2) && ([/ping GOOGLE count=3 size=28]<2)) || (([/ping YAHOO count=3 size=28]<2) || ([/ping GOOGLE count=3 size=28]<2)))) do={/tool netwatch set [find host=“1.2.3.4”] disabled=yes} else={/tool netwatch set [find host=“1.2.3.4”] disabled=no}

I would just do the two seperate scripts…
If both time out; AND
:if (([/ping YAHOO count=3 size=28]<2) && ([/ping GOOGLE count=3 size=28]<2)) do={/tool netwatch set [find host=“1.2.3.4”] disabled=yes} else={/tool netwatch set [find host=“1.2.3.4”] disabled=no}

If either times out; OR
:if (([/ping YAHOO count=3 size=28]<2) || ([/ping GOOGLE count=3 size=28]<2)) do={/tool netwatch set [find host=“1.2.3.4”] disabled=yes} else={/tool netwatch set [find host=“1.2.3.4”] disabled=no}

Really it seems to me all you need to do is the OR - what does it matter if they both time out if you are going to do the same thing if either times out…logically speaking of course…

R/

YUJOBIKA-

But when the script ping to yahoo & google, why they can not ping in the same time ?
The script ping yahoo first then ping google.

Well I guess we need a lesson in logic… :slight_smile:

Scripts excute linearly. One piece at a time…

In your script below:

:if (([/ping YAHOO count=3 size=28]<2) || ([/ping GOOGLE count=3 size=28]<2)) do={/tool netwatch set [find host=“1.2.3.4”] disabled=yes} else={/tool netwatch set [find host=“1.2.3.4”] disabled=no}

First to excute is Yahoo, once it is done a ‘true’ or ‘false’ value is assigned, then the script proceeds to the next part, Google, once that is done it is also assiged a ‘true/false’ value. Now the section between the outside parens (( … )) is evaluated by the :if for the || OR condition. IF either is true do={this} IF false else={this}

Make sense now?

R/

bravo galaxynet :slight_smile:
Again…you solved my problem :wink:

Hope my boss happy and increase my sallary :smiley:

Thank You

galaxynet, would you help me one more time ?

I already had working script as follow:
:if (([/ping XXX count=10]<5) || ([/ping YYY count=10]<5)) do={…

But how to make this script ?
:if (([/ping XXX and AAA count=10]<5) || ([/ping YYY and BBB count=10]<5)) do={…

Would you tell me what variable to use for “XXX and AAA” and “YYY and BBB” ?