April 16, 2025

Network Performance Optimization with MikroTik: L3HW Offloading and Hardware Routing

How to avoid partial script execution on MikroTik

AI-translated from Italian. Have a correction? Drop us a line.

How to avoid partial script execution on MikroTik

Keep your MikroTik scripts from getting stuck in "limbo" with OptiWize's INCEPTION technique. Learn how to guarantee safe execution even when a remote session drops!

INCEPTION: How to Avoid Script "Limbo" on MikroTik The secret technique used by OptiWize (optiwize.cloud) to ensure your scripts never get stuck in the limbo of incomplete configuration.

Why should you care about "Script Limbo"? Picture this nightmare scenario: you're applying critical changes to your MikroTik router — maybe disabling an interface or installing vital updates. Suddenly, like a scripting tragedy, your remote session dies at the most crucial moment.

Plot twist:

  • Your script is trapped in limbo
  • The configuration is in an indeterminate quantum state
  • The router may have become a network zombie

To avoid this horror-movie scenario, the OptiWize team has developed a technique worthy of Christopher Nolan: INCEPTION — a script inside a script.

Just like in the film, we go one level deeper to ensure the job gets done, no matter what happens in the outside world.

The INCEPTION Architecture

  1. The Architect Script (your entry point)
  • Creates an Extractor Script that contains the real mission
  • Plants a totem scheduler that will verify reality after 1 second
  1. The Extractor Script (the true hero)
  • Executes the mission from inside the router (immune to real-world disconnections)
  • Self-destructs in 5 seconds (Mission: Impossible style)
  • On failure, leaves breadcrumbs for future debugging (like Hansel and Gretel)
  1. The Mission Log
  • Every step is documented like a Star Trek captain's log (/log warning)

Superhero Advantages

  • Disconnection Kryptonite Immunity: Your Winbox session can get sucked into a black hole and it won't matter
  • Stealth Cleanup: Like a digital ninja, it leaves no trace if the mission succeeds
  • Debug Mode On: If something goes wrong, the script remains like an Easter egg for future network archaeologists
  • Audit-proof Logs: Every action is tracked like a spy thriller
# MAIN SCRIPT: setupSchedulerScript
:log warning "Starting creation of secondary script and scheduler..."

# 1) Create the secondary script "doUpdate"
/system script add name="doUpdate" source="
:log warning \"[doUpdate] Starting script...\";
/do {
    # --- ACTIONS TO PERFORM HERE ---
    :log warning \"[doUpdate] Disabling interface ether5...\";
    /interface disable [find name=\"ether5\"];

    :log warning \"[doUpdate] Waiting 5 seconds...\";
    :delay 5;

    :log warning \"[doUpdate] Re-enabling interface ether5...\";
    /interface enable [find name=\"ether5\"];

    :log warning \"[doUpdate] Operations completed. Cleaning up...\";
    # If all OK, remove scheduler and self
    /system scheduler remove [find name=\"tempScheduler\"];
    /system script remove [find name=\"doUpdate\"];
} on-error={
    :log warning \"[doUpdate] Error during execution. Removing scheduler only...\";
    /system scheduler remove [find name=\"tempScheduler\"];
    :log warning \"[doUpdate] Script not deleted. Kept for debug.\";
    :error \"Script execution aborted.\";
};
"

# 2) Create the scheduler "tempScheduler" that will run "doUpdate" in 1 second
/system scheduler add name="tempScheduler" \
    on-event="do {/system script run doUpdate;}" \
    start-time=startup delay=1s interval=0s disabled=no

:log warning "Script and scheduler creation complete. The script will run in 1 second."

How we use it in OptiWize In our arsenal at optiwize.cloud, this inception technique is essential whenever MikroTik devices need to:

  • Receive top-secret orders (new configurations)
  • Update their arsenal (patches and packages)
  • Execute undercover operations (scheduled maintenance)

Jedi Network Pro-Tips

  1. The Star Trek Rule: Always test on a holodeck (staging environment) before the real mission
  2. The Superman Principle: Verify your user's superpowers (privileges)
  3. The Doctor Who Law: Make sure script names are unique across the space-time continuum
  4. The Sherlock Protocol: Always monitor the logs for clues
  5. The Batman Backup: Always prepare for the worst with a fallback plan

Conclusion This inception technique — a script that spawns another script, triggered by a totem scheduler — is our way of hacking around the limitations of the API/SSH/Winbox universe.

As they say in Mission: Impossible: "This script will self-destruct in 5 seconds. Good luck, administrator."

May the Force be with your scripts! 🖖

Subscribe to our newsletter!

Stay up to date on industry topics and OptiWize features

    • Required field
  • Please enter a valid email address

  • Please enter a valid name

  • Please enter a valid phone number

  • Value is too small

    • Required field
  • Please enter a valid email address

  • Please enter a valid name

  • Please enter a valid phone number

  • Value is too small

By clicking the button you accept our Privacy Policy

Want to explore a topic further? Fill in the form and we'll get back to you as soon as possible

Email First Name Last Name Mobile Number of devices

0

10000+

    • Required field
  • Please enter a valid email address

  • Please enter a valid name

  • Please enter a valid phone number

  • Value is too small

    • Required field
  • Please enter a valid email address

  • Please enter a valid name

  • Please enter a valid phone number

  • Value is too small

Network Performance Optimization with MikroTik: L3HW Offloading and Hardware Routing — OptiWize