MikroTik Script: Router Rebooted Script

MikroTik Script: Router Rebooted Script

This is a useful little RouterOS script that will email you a nice report when your router reboots. The emailed report contains recent critical log events that may point you to the cause for the reboot. ie “router was rebooted without proper shutdown” or “out of memory condition was detected”.

The Router Reboot Script

Install the script

Using Winbox, copy and paste the above script into System | Scripts on your MikroTik Router.  The script should be named router-reboot-report.  Here is a screenshot of the installed routeros script.

Setup script to run on Startup

After you have added the script, navigate to System | Scheduler and create a new schedule to run on startup. Here is a screenshot of what the schedule looks like.

Mikrotik Winbox Scheduler Screenshot

We want the script to run every time the router reboots so from the Start Time dropdown choose “startup

In the On Event section of the schedule paste the following commands.

The script name should exactly match the name of the script you added.  The 30 second delay gives the router a chance to get connectivity after reboot.  If the email fails to send then you may need to increase the delay.

Configure Logging

For this script to function properly you must configure persistent logging on your MikoTik Router.  If your logs are not persistent across reboots you may miss some of the critical log events that tell the story of why it reboot in the first place.  To configure persistent logging please see the Logging page on the mikrotik wiki.

Example Email Report

This is what the report looks like, you will receive this email each time your router reboots.  As you can see in the example my router recently rebooted with an out of memory condition.  The report also provides the current version RouterOS packager version as well as the firmware version information.

This script can help troubleshoot random reboots and unexpected crashes. I hope you find this MikroTik Script useful!

Leave a comment below or checkout my other MikroTik Tutorials.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.