Calling Mikrotik script from Shell script

Hello all,

I’m completely new to Mikrotik scripting so forgive me if this is a simple question. I’m trying to turn on and off my ethernet connection depending on a true/false from a shell script I’ve got. Effectively, I want to trigger a Mikrotik script from a shell script. Is this possible? Some example code would be greatly appreciated!

Thank you for your time!

why not use ssh ?

ssh admin@mikrotik /interface/ethernet/etherX/set enabled false

something like that. if you set up the public key or use sshpass then you also won’t need to authenticate each time so it can be added to a script

/interface/ethernet/etherX/set enabled false on v7 work???

/interface ethernet set ether<X> disabled=yes



/system script run <SCRIPTNAME>

Thanks @fragtion and @rextended for your quick replies.

Yup those seem to be reasonable ways of calling shell scripts from MikroTik scripts (I’m assuming since they start with /interface or /system) but I’m actually looking to call a MikroTik script from a shell script. I’ll provide a simple example below

#!/bin.sh

filename=`basename "$0"`
for pid in $(pidof -x $filename); do
	if [ $pid != $$ ]; then
		echo  "Process is already running with PID $pid"
		# Call MikroTik script here to open connection
		# Do something with open connection
		# Call MikroTik script here to close connection
	fi
done

Sorry for asking a vague question earlier and thanks for your time!

Combine the previous answers like so:

ssh admin@mikrotik /system script run <SCRIPTNAME>