Community discussions

MikroTik App
 
drdrdr
just joined
Topic Author
Posts: 19
Joined: Thu Apr 05, 2007 1:55 pm
Location: Serbia

remote ssh via script

Fri Mar 29, 2013 2:13 pm

Hi,

I have script that should run command on remote mikrotik. I made keys and tested it. It works. But problem is to put it in script.

This script named "disable_ether5" looks like this:
/system ssh 172.19.3.12 "/interface ethernet disable ether5"
If I run it in terminal like this:
/system script run disable_ether5
it works, but if I press "Run Script" button in winbox it does not work.

Main problem is that it also does not work in Netwach.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: remote ssh via script

Sat Mar 30, 2013 12:04 am

I had this problem a while back using v5.7: http://forum.mikrotik.com/viewtopic.php?f=9&t=62260, never found an answer... but I have not tried it again on more recent versions.

MikroTik says Netwatch won't work with private keys: http://forum.mikrotik.com/viewtopic.php ... 13#p337605
 
drdrdr
just joined
Topic Author
Posts: 19
Joined: Thu Apr 05, 2007 1:55 pm
Location: Serbia

Re: remote ssh via script

Mon Apr 01, 2013 12:25 am

Thank you. They should make it possible to give owner of netwach.
 
User avatar
jgellis
Member Candidate
Member Candidate
Posts: 139
Joined: Wed May 30, 2007 10:57 am
Location: USA

Re: remote ssh via script

Mon Apr 01, 2013 5:56 pm

I have used the following work around in several other scripts, it may work for you as well (even to answer the netwatch issue).

Create the desired script as a scheduler event (in this example it will be named "netwatchsch1".
In your netwatch action, update the scheduled start-time to 1 second in the future using the following:
/system scheduler set [find name=netwatchsch1] set start-time=([/sys clock get time] + 0:0:1)
This will allow a Netwatch action to execute under the user that created the scheduled event and thus, should overcome the certificate issues. Remember that the certificates of the scheduled event owner will be used and the scheduled event owner is the user that created the event in the first place.
 
drdrdr
just joined
Topic Author
Posts: 19
Joined: Thu Apr 05, 2007 1:55 pm
Location: Serbia

Re: remote ssh via script

Tue Apr 02, 2013 1:03 am

When I read your message it all sounded logic, and I thought "This is it!", but it does not work.
I did not even used Netwach. I only made Scheduler that is trigering every two seconds, but nothing hapends. Trigering script from terminal still works.
I only have one user on both routers (admin), so owner of keys, scripts and scheduler is same.

PS.
I have deleted keys on both routers, but sending commands from terminal still worked. I was frustrated, then I noticed that if username and password are same on both routers, keys are not needed. I changed password, and used keys for further testing.

I have used v5.24 on RB450 on both routers. I have also tested this on clean mikrotiks in VMware.

Thank you
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: remote ssh via script

Tue Apr 02, 2013 4:50 pm

everything that looks suspiciously interactive, like ssh login or telnet login will not work if ran from scheduler or script.
 
scampbell
Trainer
Trainer
Posts: 487
Joined: Thu Jun 22, 2006 5:20 am
Location: Wellington, NZ
Contact:

Re: remote ssh via script

Thu May 16, 2013 9:41 pm

I have a similar issue, running RoS 5.24. I have set up the user admin-ssh on both routers, given them FULL rights (for now), and loaded the Public Key on the Host and Private & Public Keys on the client.

The script owner is admin-ssh

If I execute the script from a New Terminal in Winbox (logged into Winbox as admin-ssh on the client router) and do "/system script run scriptname" it works with no interaction.

If I try and run the same script in the same Winbox session (logged in as admin-ssh) by selecting it from the script list and select Run Script it starts and logs the first info message but gets no further. Anything from the SSH command onwards is not executed.

No sign of a connection attempt on the host router in the ssh debug log either.

Here is the script:-

/log info "Running SSH test"
/system ssh x.x.x.x user=admin-ssh "/log error \"Here I am\"";
/log error "SSH Communicated to x.x.x.x";
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: remote ssh via script

Fri May 17, 2013 4:35 pm

it is not possible to execute interactive commands from other scripts via script.

If you open terminal it is OK
if that is done via script = nothing happens.
 
P0intLess
just joined
Posts: 3
Joined: Wed May 15, 2013 9:27 am

Re: remote ssh via script

Fri Nov 08, 2013 2:02 pm

Still no progress on the problem? 6.6 is already out today... Oh when we routeros users will be happy to have remote ssh commands called from scripts working?... :-x
 
Ehman
Member
Member
Posts: 389
Joined: Mon Nov 15, 2010 10:49 pm

Re: remote ssh via script

Mon Dec 09, 2013 6:59 pm

This is lame... I want to make a script that change somethings on 20 AP's via ssh, but hmmmm nooo ...I cant! ...because Mikrotik doesn't want me to be lazy, and Mikrotik wants me to login into each router and change stuff. I don't get the point of not allowing it, I like my stuff to be automated, I like my scripts to run then I'm drinking or sleeping or out, if a problem gets detected I want a script to run, can't here... Mikrotik :?
 
Ehman
Member
Member
Posts: 389
Joined: Mon Nov 15, 2010 10:49 pm

Re: remote ssh via script

Mon Dec 09, 2013 7:04 pm

it is not possible to execute interactive commands from other scripts via script.

If you open terminal it is OK
if that is done via script = nothing happens.
/system ssh 1.2.3.4 user=admin "/log print "hello";
It asked me for a password, I want to put my password into my scripts, and btw, it takes a password to log into my routers, but I want my routers to give each other commands when triggered
 
pwuk
Frequent Visitor
Frequent Visitor
Posts: 51
Joined: Wed Aug 01, 2012 8:51 pm

Re: remote ssh via script

Sun Dec 15, 2013 11:08 am

Well you get around the requirement for interaction and passwords by using ssh keys, however that doesn't help when you run the script from the scheduler

Here's my script:
add name=remotebackup policy=read,write,test source="/log info \"start backup\"; /log info \"Get R1\"; /system ssh 1.2.3.4 user=backup \"export compact\" output-to-file=autobackup_R1 ; /log info \"end backup\""

When you run /system script run 0
(R0) 08:59:46 script,info start backup
(R0) 08:59:46 script,info Get R1
(R1) 08:59:46 ssh,info publickey accepted for user: backup
(R1) 08:59:46 system,info,account user backup logged in from 1.2.3.4 via ssh
(R1) 08:59:47 system,info,account user backup logged out from 1.2.3.4 via ssh
(R0) 08:59:47 script,info end backup

However when the scheduler runs
09:01:21 script,info start backup
09:01:21 script,info Get R1

And that's it, when the scheduler runs the script it doesn't even attempt to log in -- no traffic on the wire.
 
drdotti
just joined
Posts: 16
Joined: Sat Mar 17, 2012 4:15 pm

Re: remote ssh via script

Sun Jan 05, 2014 7:08 pm

Hi,

i have the same Problem.

http://forum.mikrotik.com/viewtopic.php ... 01#p402501

mfg

Klaus
 
maliha
just joined
Posts: 1
Joined: Tue Jan 07, 2014 7:34 pm

Re: remote ssh via script

Tue Jan 07, 2014 7:57 pm

I think you need to escape the special characters in the string

Sent from my SCH-I545 using Tapatalk
 
jumanor
just joined
Posts: 1
Joined: Sat Sep 20, 2014 4:46 am

Re: remote ssh via script

Sat Sep 20, 2014 4:54 am

hello
I have the same problem
It's frustrating !!!!!! :(
 
xollis
just joined
Posts: 4
Joined: Wed Aug 26, 2015 3:13 am

Re: remote ssh via script

Wed Sep 09, 2015 12:14 am

Did this ever get resolved? I am having a similar issue and was hoping to find an answer.
 
voz
just joined
Posts: 5
Joined: Tue Sep 29, 2015 4:03 pm

Re: remote ssh via script

Tue Sep 29, 2015 4:24 pm

Two years and a half! the issue still there and no solution from mikrotik.
that's really cool!
here is my scenario. I have router and the NAS. script saves config then logs in to NAS and run auto-fetching ftp command to get backup config file
/log info message="Backup run";
/system backup save name=backup/auto.backup; 
/log info message="pre SSH"; 
/system ssh user=<user> address=<host> command="ftp ftp://<backup_user>:<pass>@router/%2Fbackup%2Fauto.backup -o /<path to backup>/auto-`date +%F`.backup"
/log info message="post SSH"; 
script works from terminal, but doesn't by click the RunScript button in webfig nither by Scheduler event - it fails after pre SSH message

the only way I see - run my script by ssh login from NAS via crond :lol:
 
satish143
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Jan 22, 2016 9:54 pm

Re: remote ssh via script

Thu Apr 07, 2016 9:48 pm

Guys! any solution? I need this option bady to sync two VRRP MT. This is stupid issue. why SSH not allowed to run over script? :? :? :?
 
satish143
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Jan 22, 2016 9:54 pm

Re: remote ssh via script

Thu Apr 07, 2016 9:48 pm

Guys! any solution? I need this option bady to sync two VRRP MT. This is stupid issue. why SSH not allowed to run over script? :?
 
voz
just joined
Posts: 5
Joined: Tue Sep 29, 2015 4:03 pm

Re: remote ssh via script

Fri Apr 08, 2016 3:33 pm

Guys! any solution? I need this option bady to sync two VRRP MT. This is stupid issue. why SSH not allowed to run over script? :?
You not feel the Power of ssh-script-running, don't You? It's too dangerous :lol:

Ok. Why 3-d host cron task is not the solution for You? It really works for me very well.
 
peter1024
just joined
Posts: 1
Joined: Wed Jun 15, 2016 11:41 am

Re: remote ssh via script

Wed Jun 15, 2016 11:53 am

Hello ,

I have the same problem . I wrote a script that logs on to  AirOS then it make reboot . If it does from terminal everything works . Unfortunately, the schedule of tasks script does not work. Do not execute the line :
/System ssh address=10.0.0.200 user=admin command=reboot
If you paste this command into the terminal , everything works correctly

Is there already a solution to this problem?
 
Wyz4k
Member Candidate
Member Candidate
Posts: 240
Joined: Fri Jul 10, 2009 10:23 am

Re: remote ssh via script

Sat Nov 05, 2016 5:00 pm

Hi there,

I can confirm that this is still not possible in 6.37.1
 
Permanentik
just joined
Posts: 1
Joined: Mon Sep 25, 2017 1:08 pm

Re: remote ssh via script

Mon Sep 25, 2017 2:32 pm

Up 2017
 
johanfirdi
just joined
Posts: 2
Joined: Thu Oct 15, 2009 9:12 am

Re: remote ssh via script

Sat Nov 11, 2017 2:23 pm

I get the same problem above.
run remote ssh script via terminal works, BUT
not WORK in script mode.
my case is creating dynamic gre tunnel after pppoe interfaces up,
dynamic because public ip address assigned dynamically. I need to ssh remote machine to do create tunnel.
i create in linux, work normally by editing /etc/ppp/ip-up to custom script.
But get problem when porting to mikrotik.
work in terminal.
not work in script.
 
OKNET
Member
Member
Posts: 353
Joined: Mon Jun 22, 2015 9:22 am

Re: remote ssh via script

Thu Dec 14, 2017 11:47 pm

Almost 2018

After years and years same issue (no single line ssh client connecting automatically to remote ssh server by script)

At least , someone from mikrotik staff should clearly say : "it is not possible and it will be not possible because we don't want it to be possible"

People still remain hangings with hope......

Any info please ?
 
RavenWing71
newbie
Posts: 34
Joined: Thu May 12, 2011 3:52 am

Re: remote ssh via script

Fri Dec 29, 2017 9:32 pm

This may not directly relate, but I was having a similar problem getting a script to use fetch to upload a file. It turned out that the script had to have the "test" policy checked?!? You might give it a try.
 
Wyz4k
Member Candidate
Member Candidate
Posts: 240
Joined: Fri Jul 10, 2009 10:23 am

Re: remote ssh via script

Sat Dec 30, 2017 5:53 pm

Nope, it's not a privilege thing. It's functionality not allowed by Mikrotik
 
User avatar
hughrobbie
just joined
Posts: 10
Joined: Wed Apr 15, 2015 2:29 pm
Location: KZN
Contact:

Re: remote ssh via script

Wed Jan 10, 2018 3:26 pm

If you have a windows machine, you can use plink.exe and create a SSH batch file to run your script on your Mikrotik and schedule the batch file with windows scheduler.
If anybody needs help with this, let me know. :)
 
User avatar
che
Member Candidate
Member Candidate
Posts: 111
Joined: Fri Oct 07, 2005 1:04 pm

Re: remote ssh via script

Wed Jan 10, 2018 3:44 pm

I have uploaded to Github my old Python script that does what you need: connects to a number of different Mikrotik routers and then executes some commands. All you need to do is edit username and password in .py file, list of IP addresses and commands.

The only requirement is that you have Python installed with paramiko module on either Windows, Linux or MacOS machine.

mikrotik-distributed-ssh
 
SX1
just joined
Posts: 3
Joined: Thu Dec 22, 2016 5:21 pm

Re: remote ssh via script

Thu Jan 11, 2018 3:36 pm

Same trouble using Dude Notifications. I wanted to create some type of alarm using ssh and beep when any device down. But it's not work because Mikrotik team don't want to activate remote ssh via script.
What's wrong with you, Mikrotik? It's a great fail!
 
markovip
just joined
Posts: 4
Joined: Thu Jan 18, 2018 1:23 pm

Re: remote ssh via script

Sat Feb 03, 2018 5:23 pm

I'm also waiting for this GREAT capability!
 
dadoremix
Member Candidate
Member Candidate
Posts: 133
Joined: Sat May 14, 2011 11:31 am

Re: remote ssh via script

Sat Feb 03, 2018 7:34 pm

Maybe for 10 years mikrotik make a app for remote control 100+ devices
 
ingus16
newbie
Posts: 29
Joined: Sun Jan 27, 2013 11:44 am

Re: remote ssh via script

Wed Mar 07, 2018 3:25 am

Need this feature BADLY..
Please do something
 
zivtal
Frequent Visitor
Frequent Visitor
Posts: 57
Joined: Sun Feb 05, 2017 6:22 pm

Re: remote ssh via script

Mon Mar 19, 2018 3:37 pm

Made this long time ago, maybe it's will help you...
:local router2address "192.168.88.1";
:local router2interfaces "sfpp1,sfp1,vlan9";
:local router2username "user1";

:local SetInterface do={
	:local interfaces [:toarray $1];
	:local mode [:tostr $2];
	:local host $3;
	:local user [:tostr $4];
	:local cmd;
	#Set diabled bollean (true/false)
	:local disabled; :if ($mode="disable") do={:set $disabled true;} else {:set $disabled false;}
	#If host not set, interfaces are local
	if ([:typeof $host]="nothing") do={
		#Host wasn't set, then set local interfaces
		foreach interface in=[:toarray $interfaces] do={
			if ([:len [/interface find name=$interface]]>0) do={
				if ([/interface get value=disabled $interface]!=$disabled) do={
					/interface set disabled=$disabled $interface
					:log info ([/system clock get time]." '$interface' has been ".$mode."d.\r\n");										
				}
			} else {
				:log info ([/system clock get time]." '$interface' not exists.\r\n");
			}
		}
	} else {
		#Host has been set, then create ssh's command for sending
		foreach interface in=[:toarray $interfaces] do={
			:set $cmd ($cmd."if ([:len [/interface find name=$interface]]>0) do={	if ([/interface get value=disabled $interface]!=[:tobool $disabled]) do={		/interface set disabled=[:tobool $disabled] $interface;		:log info \"'$interface' $mode command has been received from '$[/system identity get name]' (via ssh).\"		} else {			:log warning \"$mode command from '$[/system identity get name]' (via ssh) was denied, '$interface' already $mode.\" 		}} else { :log error \"$mode command from '$[/system identity get name]' (via ssh) was failed, '$interface' not exists.\" }\r\n");
			:log info ([/system clock get time]." '$interface' $mode command has been sent to '$host' via ssh ($user).\r\n");
		}
		#Check if host responding
		if ([/ping $host count=1]>0) do={
			#Host response, connect to host and send command
			do {
				/system ssh $host user=$user command=$cmd
			} on-error={
				#Error caold not connect to host
				:log info ([/system clock get time]." $mode command was not sent, could not connect to 'host'.\r\n");
			}
		} else {
			#Host not respoding
			:log info ([/system clock get time]." $mode command was not sent, 'host' not responding.\r\n");
		}		
	}
}
$SetInterface $router2interfaces disable $router2address $router2username
 
gerakon
Member Candidate
Member Candidate
Posts: 105
Joined: Sat May 24, 2014 8:14 am

Re: remote ssh via script

Wed Mar 21, 2018 3:06 pm

I had a similar problem years ago that I wanted to reboot some crappy engenius APs every night on a schedule so they wouldn't lock up once a week. I suspect Mikrotik doesn't allow this because it could turn their routers into a weapon for hackers. Any way, I looked into using API at the time, but didn't understand it well enough to implement, but it looked like it might work.
 
gogasan
just joined
Posts: 1
Joined: Wed Apr 04, 2018 1:33 pm

Re: remote ssh via script

Wed Apr 04, 2018 1:36 pm

Now %DATE% already. Still wont working.
Trying to setup configuration replication using scheduler. Wont it working in manual mode.
 
electravis
Member Candidate
Member Candidate
Posts: 274
Joined: Tue Jan 26, 2010 12:06 am

Re: remote ssh via script

Mon Aug 06, 2018 6:34 pm

Any update to allowing ssh to run in a script? Today I needed this functionality for the first time and after a few hrs of failure i googled and found everyone else with the same issue.
 
TT12
just joined
Posts: 3
Joined: Fri Sep 07, 2018 11:55 am

Re: remote ssh via script

Fri Sep 07, 2018 12:27 pm

I have uploaded to Github my old Python script that does what you need: connects to a number of different Mikrotik routers and then executes some commands. All you need to do is edit username and password in .py file, list of IP addresses and commands.

The only requirement is that you have Python installed with paramiko module on either Windows, Linux or MacOS machine.

mikrotik-distributed-ssh
Hello,
is it possible to change your script to join with RSA key connection with a password + specific username?
Thank you
 
Posse7x
just joined
Posts: 12
Joined: Thu Oct 06, 2016 4:11 pm

Re: remote ssh via script

Tue Sep 11, 2018 3:55 pm

hello,

no solution but a work around

not running the ssh command via a script -> importing them via an rsc file

/system scheduler add name=run_sshscript interval=24:00:00 start-time=00:00:00 start-date=jan/01/1970 on-event="/import file=sshscript.rsc"

the commands (system ssh x.x.x.x command="") is stored in the rsc files

regards
 
User avatar
che
Member Candidate
Member Candidate
Posts: 111
Joined: Fri Oct 07, 2005 1:04 pm

Re: remote ssh via script

Tue Sep 11, 2018 4:15 pm

Hello,
is it possible to change your script to join with RSA key connection with a password + specific username?
Thank you

Could you clarify the question a bit? As I understood, you want the script to know which hosts use which usernames, passwords and keys, with same host having multitude of those?
 
TT12
just joined
Posts: 3
Joined: Fri Sep 07, 2018 11:55 am

Re: remote ssh via script

Tue Sep 11, 2018 4:44 pm

Hello,
is it possible to change your script to join with RSA key connection with a password + specific username?
Thank you

Could you clarify the question a bit? As I understood, you want the script to know which hosts use which usernames, passwords and keys, with same host having multitude of those?
Hi,
sorry for my english:
I already changed your script to allow join only with RSA private key (on mikrotik is imported public):

add: k = paramiko.RSAKey.from_private_key_file('key.ppk')
ssh.connect(host,username=mt_username,pkey=k,timeout=timeout)

this way allows you to connect to ssh only with the private ssh key - without login + password.
The problem occurs when I generate ssh (RSA) keys in PuttyGEN - the paramiko module reports a ssh key format error.
If I generate ssh keys over paramics, everything is fine.
Is it possible to add the ability to generate the most secure pairs of private and public keys compatible with mikrotik?
Probably RSA 4096 - with password (aes-128-ctr)
Signing in with ssh keys is a much safer method.
Thank you for the info.
 
User avatar
che
Member Candidate
Member Candidate
Posts: 111
Joined: Fri Oct 07, 2005 1:04 pm

Re: remote ssh via script

Tue Sep 11, 2018 5:34 pm

While I agree that using key pairs is the best practice from security standpoint, my script was not aiming at that particular scenario. My network had few hundreds of MikroTik boxes that needed to be changed quickly and zero key pairs setup beforehand. I was sitting on Windows desktop machine and came up with mentioned script.

Regarding ssh server on MikroTik, you can read up on what crypto they use with "strong crypto" option off/on: https://wiki.mikrotik.com/wiki/Manual:IP/SSH

I'm not sure about other key and certificate limitations on RouterOS.
 
Wyz4k
Member Candidate
Member Candidate
Posts: 240
Joined: Fri Jul 10, 2009 10:23 am

Re: remote ssh via script

Wed Sep 12, 2018 8:21 am

hello,

no solution but a work around

not running the ssh command via a script -> importing them via an rsc file

/system scheduler add name=run_sshscript interval=24:00:00 start-time=00:00:00 start-date=jan/01/1970 on-event="/import file=sshscript.rsc"

the commands (system ssh x.x.x.x command="") is stored in the rsc files

regards
Useful, but only if you can login without a password as the /system ssh prompt does not allow you to enter in the password in the connect string.
 
Posse7x
just joined
Posts: 12
Joined: Thu Oct 06, 2016 4:11 pm

Re: remote ssh via script

Wed Sep 12, 2018 11:19 am

it works with ssh key
you just need to create the scheduler and script with the account linked to the private key.
 
Wyz4k
Member Candidate
Member Candidate
Posts: 240
Joined: Fri Jul 10, 2009 10:23 am

Re: remote ssh via script

Thu Sep 13, 2018 3:20 pm

it works with ssh key
you just need to create the scheduler and script with the account linked to the private key.
I tried this, but could not get it going. If I manually call the script from the terminal it works fine and connects to ssh, but if I run it with a schedule it doesn't execute and gives a script error, or nothing.
 
Posse7x
just joined
Posts: 12
Joined: Thu Oct 06, 2016 4:11 pm

Re: remote ssh via script

Tue Sep 18, 2018 10:25 am

as i said

you need to create a .rsc file (eg: /system ssh x.x.x.x command="/interface disable ether1")

safe it as script.rsc

then create the scheduler:

/import script.rsc verbose=yes

you'll see the script starting and where it gets interrupted
 
Wyz4k
Member Candidate
Member Candidate
Posts: 240
Joined: Fri Jul 10, 2009 10:23 am

Re: remote ssh via script

Tue Sep 18, 2018 10:46 am

as i said

you need to create a .rsc file (eg: /system ssh x.x.x.x command="/interface disable ether1")

safe it as script.rsc

then create the scheduler:

/import script.rsc verbose=yes

you'll see the script starting and where it gets interrupted
I'd love to be proven wrong, but that doesn't work. I've just tried it again in 6.42.7. What version are you running it on?
If I run "/import script.rsc verbose=yes" from terminal it logs in fine on the other side.

script.rsc contains only "/system ssh address=IP user=USER command=quit"

If I create a scheduler and add "/import script.rsc verbose=yes" to it, it just doesn't do anything.

If I add a print before the /system ssh command and one after, it only prints the before command which indicates that it breaks on the /import command.
 
User avatar
amb3r
just joined
Posts: 16
Joined: Fri Oct 31, 2014 8:35 am

Re: remote ssh via script

Mon Sep 24, 2018 8:58 am

hello,

no solution but a work around

not running the ssh command via a script -> importing them via an rsc file

/system scheduler add name=run_sshscript interval=24:00:00 start-time=00:00:00 start-date=jan/01/1970 on-event="/import file=sshscript.rsc"

the commands (system ssh x.x.x.x command="") is stored in the rsc files

regards
im really interested with the solution you made. do i need to input username/passsword on the ssh command in .rsc? do you have a sample script sir?
 
TT12
just joined
Posts: 3
Joined: Fri Sep 07, 2018 11:55 am

Re: remote ssh via script

Wed Oct 03, 2018 11:00 pm

Hi,
i found better solution for multiple config mikrotiks via ssh:
Software: MobaXterm
create and save different mikrotik sessions, then run from menu MultiExec
now you can type commands multiple in all terminals - run script working :)
 
Wyz4k
Member Candidate
Member Candidate
Posts: 240
Joined: Fri Jul 10, 2009 10:23 am

Re: remote ssh via script

Thu Oct 04, 2018 2:30 am

hello,

no solution but a work around

not running the ssh command via a script -> importing them via an rsc file

/system scheduler add name=run_sshscript interval=24:00:00 start-time=00:00:00 start-date=jan/01/1970 on-event="/import file=sshscript.rsc"

the commands (system ssh x.x.x.x command="") is stored in the rsc files

regards
im really interested with the solution you made. do i need to input username/passsword on the ssh command in .rsc? do you have a sample script sir?
His solution doesn't work, or at least doesn't work any more. I've asked him for more details and he hasn't been forthcoming.
Hi,
i found better solution for multiple config mikrotiks via ssh:
Software: MobaXterm
create and save different mikrotik sessions, then run from menu MultiExec
now you can type commands multiple in all terminals - run script working :)
This post is about connecting to a remote router via a script. As you can't run MobaXterm on the router, that is not an applicable solution to the problem.
 
floryluc
just joined
Posts: 5
Joined: Tue Nov 18, 2014 11:46 am

Re: remote ssh via script

Wed Jul 24, 2019 6:34 pm

hi everybody, for very long time i whose waiting for Mikrotik solutions for the remote ssh connection, finally the solutions is on way

https://wiki.mikrotik.com/wiki/Manual:S ... ertificate

SSH-exec
Sub-menu: /system ssh-exec
Command ssh-exec is a non-interactive ssh command, thus allowing to execute commands remotely on a device via scripts and scheduler.

on v6.45.1 is implemented

As I have seen that several of you are in the same problem, I decided to share it with the whole community

a greeting
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1782
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: remote ssh via script

Wed Jul 24, 2019 10:51 pm

That's just part of the solution. ssh-exec requires use of PKI, while the available documentation relates to real users only
 
Wyz4k
Member Candidate
Member Candidate
Posts: 240
Joined: Fri Jul 10, 2009 10:23 am

Re: remote ssh via script

Thu Jul 25, 2019 3:17 am

As I have seen that several of you are in the same problem, I decided to share it with the whole community
Thank you floryluc! Very nice of you to post this here. I will definitely give it a bash.
 
mimbach
just joined
Posts: 14
Joined: Fri Sep 14, 2007 7:59 am
Location: utah / wyoming

Re: remote ssh via script

Sun Oct 24, 2021 3:28 am

The ssh-exec command does work for me in a script via scheduler using RouterOS version 6.49.
Thank you!

Who is online

Users browsing this forum: No registered users and 16 guests