linuxscriptingroutesmikrotikrouter-os

Miktotik - routing script


I'm stuck at doing this script. Script is supposed to do this:

It will download a file from URL. If it reach the file and downloads it then changes routing to Server 1. If download failed it will change routing to Server 2. Then it'll delete that file from router memory.

Download should be via command: /tool fetch url="" and then something like
 :if ( true ) do (/ip routing .....) 
and 
:if ( false ) do (/ip routing ....) 

I hope you get me and you can help me creating this script.


Solution

  • Make 2 schedules that repeat once every hour/10mins(it's up to you) and have the start times separated by 10 seconds or more depending on the file size or connection speed.

    First script deletes existing file and redownloads it:

    /file remove index.php
    /tool fetch url="http://example.com/index.php"
    

    And the second one checks if the file exists:

    :if ([/file find name=index.php]="") do={
    #commands if download was not succesful and file does not exist
    } else={
    #commands if download was succesful and file exists
    }