Help my simple script

Hi,
I’m trying some script on my RB something like this:

/tool e-mail send
to=myemail@tiscali.it
subject=“testing script”

this script is Ok

:if ([/ping 208.67.222.222 count=5] = 0) do={
/tool e-mail send
to=“myemail@tiscali.it
subject=([/system identity get name] . " Reboot Router 3")
}

I would like the script make a 5 ping to 208.67.222.222 (Open DNS), and when it fails it must send me an SMS alert.

I’m trying two conditions
:if ([/ping 208.67.222.222 count=5] = 0) fails I think
:if ([/ping 208.67.222.222 count=5] = 1) ping Ok

but RB does’nt send email alert.

Some ideas?

Cetalfio

There is no need for script like that. Use netwatch feature of Mikrotik. It can ping specified address and if fails then run script to send mail or whatever you need.

Thanks pedja,
but I’ld like to know what is wrong in this simple script, somenthing syntax perhaps. I think that when there is some error, script does’nt execute from OS,
Cetalfio

ping returns the number of pings that are successful.
/ping xxx.xxx.xxx.xxx count=5
returns 5 if all pings are successful.

I thought this but when I read scripting documentation I do’nt find a syntax error on my script but the script does not run and therefore the email doesn’t start.

:if ([/ping 208.67.222.222 count=5] = 0) do={
/tool e-mail send
to=“myemail@tiscali.it
subject=([/system identity get name] . " Reboot Router 3")
}

Cetalfio

You have to specify mail servers IP and from address also.

Can you send email just by typing these lines in console?
/tool e-mail send
to=“myemail@tiscali.it
subject=([/system identity get name] . " Reboot Router 3")

Hi mrz,
I first set the parameters smtp from tools → email

Server and From

I need to set again in the script..

Cetalfio

Hi Cetalfio

That script works here. Well, it works like you have it written. If you change the ip to one that does not exist or does not answer a ping, it sends the email. Sent one to me anyway.

Try this:

:if ([/ping 68.99.58.122 count=5] = 0) do={
/tool e-mail send \
to="myemail@tiscali.it" \
subject=([/system identity get name] . " Reboot Router 3")
}

That ip will not answer a ping.