Running a script from an executable?

Hi Guys

Is it possible to create a simple executable that can log into a remote Mikrotik and run a script?

I’m sure it is possible but could somebody give me an example of the syntax required to log into the mikrotik and were to place the script name?

Thanks alot

if you want to run just single command you can do that through SSH. just add certificates, so you are not required to enter password, and add command after the ssh command

i am running this from linux:

$ssh admin@10.5.51.1 -i key "/ip address print"
Flags: X - disabled, I - invalid, D - dynamic 
 #   ADDRESS            NETWORK         BROADCAST       INTERFACE              
 0   10.5.51.1/24       10.5.51.0       10.5.51.255     ether1

that way you can call all CLI commands that way. In case of SSH by default you will get output to stdout.

thanks janisk

Is it possible to run that SSH command from a windows executable?, ie a .exe or a .bat?

Reason I ask is because I have a windows based monitoring program that monitors latency and can launch an executable if the latency exceeds a certain level. So if the latency goes over say 100ms then I want to launch an executable that will log into the mikrotik and increase the cost of that OSPF interface.

I would obviosuly need to create a unqiue executable for each highsite but thats fine

This is a bit off your original question, but I wanted to add that you can do this directly on RouterOS with a script.

This script will test latency using ‘/ping’. You can set threshold limits and directly execute a command if threshold latency is exceeded.

# Tests latency

# Set to an IP address (ex. 192.168.1.1) or
# a host name (ex. [:resolve "google.com"])
:local address 192.168.1.1

# Set to latency threshold limit in ms
:local maxthreshold 300

:if ([/ping address=[:toip $address] \
                interval=[:totime ($maxthreshold . "ms")] \
                count=1] = 0) do={
      :log warning ("Ping " . $address . " exceeded latency of " . $maxthreshold . "ms")
} else={
      :log info ("Ping " . $address . " with latency at/below " . $maxthreshold . "ms")
}

thank you soo much for that script!! :slight_smile:

I have never been able to get the latency reading back so thanks soo much :slight_smile: