Community discussions

MikroTik App
just joined
Topic Author
Posts: 1
Joined: Tue Dec 04, 2018 7:10 pm

Need help to email ping results / mode button event

Tue Dec 04, 2018 7:24 pm

I apologize for being a nube... can't tell you how many times I have taken a run at learning how to script but often find myself stuck at step1. (I am sure this is very simple to do.)

I would like to have create a script to ping a destination ( and email results in body of email with hostname, current date and time. I figure that this can be done multiple ways using ping speed, netwatch and such so advice on those is appreciated, but simple ping is fine.

Could someone show me how to do this.
User avatar
Forum Guru
Forum Guru
Posts: 1127
Joined: Tue Jul 21, 2015 10:09 pm
Location: UK

Re: Need help to email ping results / mode button event

Thu Dec 06, 2018 6:29 pm

You will need to set up /tools email to work correctly but when done use the below to create a script and then run the script on mode button being pressed;
#Define Email variables here
:local toEmail
:local fromEmail

#Ping Variables
:local avgRtt;

:local pin

:local pout

#Capture system identity for email subject
:local sysID [/system identity get name]

#Capture current time for logging
:local datetime "$[/system clock get date] $[/system clock get time]"

#Ping it real good
/tool flood-ping count=10 do={
:if ($sent = 10) do={
:set avgRtt $"avg-rtt"
:set pout $sent
:set pin $received


:local ploss (100 - (($pin * 100) / $pout))

:local logmsg ("Ping Average for - ".[:tostr $avgRtt]."ms - packet loss: ".[:tostr $ploss]."%")

:log info $logmsg

:log info message="Emailing Ping Test Results"
delay 2
:tool e-mail send user=$fromEmail to=$toEmail subject="Pingtest results for user $sysID" body="ID: $sysID \n Test Ran at: $datetime \n Result: \n $pingit \n $logmsg"
delay 2
:log info message="Ping Test Results Have Been Emailed"
It will email the chosen address with the below output;

"ID: honeypot
Test Ran at: dec/06/2018 16:25:56

Ping Average for - 4ms - packet loss: 0%
Steve "Steveocee" Carter
PC Gamer, Airsofter, MikroTik Nerd
My Website - My MikroTik Tutorials

Who is online

Users browsing this forum: No registered users and 23 guests