Ssh command execution failure

Hello

Im trying to do some automated updates on the routers by remote ssh commands.

so I try this

ssh username@hostname /system/identity/print

and I get the name of the router

now I try

echo “/system/identity/print” > input.txt

ssh username@hostname < input.txt

and the ssh connection hangs.

On other routers this method works without an issue.

Anyone have a hint on how to work around this?

I could upload the commands to execute into a file and upload the file but then I need a way to tell the mikrotik to execute all the commands in that file.

The other option would be to use the api but that then becomes way more complex.

Would the commands export and import help?

1 Like

/export doesn’t help here.

/import might but I can not find any documentation on it on help.mikrotik.com

Especially is /import replacing the whole config or just adding to an existing one.

Important thing to know :slight_smile:

/import path/to/file will simply execute the commands in your text file, as they are listed, and is exactly what you need.

Upload the your input.txt file and do

ssh username@hostname /import path/to/uploaded/input.txt

Have you tried, with one of these options with ssh:

-T      Disable pseudo-terminal allocation.
-t      Force pseudo-terminal allocation.

-T works. Exactly what I was looking for…

scp to file and then /import name=filename also worked.

Thanks to all

1 Like

both -T and -tt can’t work, I use ssh in Fedora 42 43 and macOS 26

What version of ssh do you use, that not support "Disable pseudo-terminal allocation" ?
I can see that dropbear ssh client dbclient also support that option.

ssh -V
OpenSSH_10.2p1, OpenSSL 3.6.0 1 Oct 2025
$

Maybe there are some another options to do the same.

And do you use ssh correctly ? Providing the username and password or using more secure one like the PKI with public and private keys.

Actually I noticed that -T or -t worked once with a small input file where it executed the second command in the input. With a large, it never worked.

So my workaround is to upload a file with scp and then execute with /input.

Ugly but works.

Sorry for not address the question to the correct user, my prev post was addressed to @mantouboji :smile:
But I can address a question to you also, is this for deployment of lots of routers configs, you could use the netinstall-cli to deploy the config, and also the newest firmware and RouterOS.(sadly not not remotely)
And also when scripting, there also you have the <CR><LF> or only <LF> or only <CR> of end of lines to think of, what the cli environment uses.

netinstall-cli is not an option

we want to use it to automatically deploy generated BGP route filters on a daily basis.

Works great on all non mikrotik routers but on the mikrotiks, the feeding of the cli with commands failed.

As I said, the workaround should work but I still dont fully understand why ssh 1.1.1.1 < inputfile is any different to ssh 1.1.1.1 and then pasting the input file into the standard input

i have the same problem :rofl:

Fedora 42:

OpenSSH_9.9p1, OpenSSL 3.2.6 30 Sep 2025

ssh -T ${router} < ${file} stops working on 7.20, and only executes the first 3 or 4 commands before hanging.

7.19.6 is the last version where this works.

1 Like

The same problem… It’s not very good to upload tons of files to execute it from router… May be any other ideas how to run multiline script from remote host?

temporary workaround is to change
ssh -T ``admin@192.168.1.1`` <<EOF $(cat commands.tmp) EOF
to
ssh -T ``admin@192.168.1.1`` $(cat commands.tmp | tr '\n' ';')

it’s bad idea for big file, but better than many hanged scripts, running by cron

1 Like

same issue on windows using kitty.

issue appeared around 7.20 or 7.20.1, and downgrading to 7.19.6 seems to mitigate the issue.

1 Like