Community discussions

MikroTik App
 
ElectricBoogaloo
just joined
Topic Author
Posts: 2
Joined: Mon Oct 17, 2022 4:08 am

Calling Mikrotik script from Shell script

Mon Oct 17, 2022 4:24 am

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!
 
fragtion
Member Candidate
Member Candidate
Posts: 257
Joined: Fri Nov 13, 2009 10:08 pm
Location: Johannesburg, South Africa

Re: Calling Mikrotik script from Shell script

Mon Oct 17, 2022 11:36 am

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
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Calling Mikrotik script from Shell script

Mon Oct 17, 2022 2:59 pm

/interface/ethernet/etherX/set enabled false on v7 work???
/interface ethernet set ether<X> disabled=yes


/system script run <SCRIPTNAME>
 
ElectricBoogaloo
just joined
Topic Author
Posts: 2
Joined: Mon Oct 17, 2022 4:08 am

Re: Calling Mikrotik script from Shell script

Tue Oct 18, 2022 2:56 am

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!
 
txfz
Frequent Visitor
Frequent Visitor
Posts: 57
Joined: Tue Mar 10, 2020 9:02 am

Re: Calling Mikrotik script from Shell script

Tue Oct 18, 2022 4:51 pm

Combine the previous answers like so:
ssh admin@mikrotik /system script run <SCRIPTNAME>

Who is online

Users browsing this forum: zandhaas and 16 guests