Community discussions

 
timmartin
just joined
Topic Author
Posts: 12
Joined: Wed Sep 01, 2010 12:01 pm

Problem sending multi-line command file via SSH

Wed Sep 01, 2010 4:23 pm

I'd like to be able to make changes to my configuration in an automated way via an SSH connection. I have a file with the following content:
/ip firewall mangle
add chain=whatever blah blah
add chain=whatever blah blah
If I type something like this at the command line it works fine. If I connect via SSH and do the same thing it works fine. But if I try and automate this process by piping it to an SSH session:
$ cat foobar.txt | ssh -i admin 192.168.88.1
Then I get the error message
bad command name add (line 1 column 1)
If I change my file to be
/ip firewall mangle add chain=whatever blah blah
/ip firewall mangle add chain=whatever blah blah
then it works, but this means modifying my script to have a lot of repeated information in it. Am I doing something obviously wrong here?
 
changeip
Forum Guru
Forum Guru
Posts: 3803
Joined: Fri May 28, 2004 5:22 pm

Re: Problem sending multi-line command file via SSH

Wed Sep 01, 2010 6:30 pm

I use semi-colons between commands, at least for short things. I don't run but a few lines on my stuff. Try using { } around your file and see if that helps.
Colo and Wholesale Bandwidth Available! Sales at SanDiegoBroadband dot com
 
timmartin
just joined
Topic Author
Posts: 12
Joined: Wed Sep 01, 2010 12:01 pm

Re: Problem sending multi-line command file via SSH

Thu Sep 02, 2010 10:10 am

Thanks for the suggestion, but braces don't seem to help. I get a 'missing closing brace' error in addition to the 'bad command name' errors if I put braces round it.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5942
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Problem sending multi-line command file via SSH

Thu Sep 02, 2010 11:49 am

Currently this is how ssh input is processed. Each line is treated as completely separate scripts that is why you get error when trying to send
/ip firewall mangle
add chain=whatever blah blah
Probably in the future it will be changed.
 
timmartin
just joined
Topic Author
Posts: 12
Joined: Wed Sep 01, 2010 12:01 pm

Re: Problem sending multi-line command file via SSH

Thu Sep 02, 2010 1:20 pm

Thanks for clarifying. Is there a good way of applying a batch of commands like this, other than FlashFig? I'll probably use FlashFig for bulk configuration of routers in a live setup, but for the moment I just want a quick way of applying a batch of commands from the command-line while I'm developing.

The best way I've found is to copy the file across with SCP and execute it on the router, which seems to work fine.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5942
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Problem sending multi-line command file via SSH

Thu Sep 02, 2010 1:55 pm

Yes, best way is to upload file and execute it on a router.
 
User avatar
davidnvega
just joined
Posts: 19
Joined: Wed Aug 28, 2013 11:11 pm
Location: San Juan, Argentina
Contact:

Re: Problem sending multi-line command file via SSH

Fri Dec 09, 2016 8:03 pm

Currently this is how ssh input is processed. Each line is treated as completely separate scripts that is why you get error when trying to send
/ip firewall mangle
add chain=whatever blah blah
Probably in the future it will be changed.
That still being a problem?? Thanks!
Sorry for my English, I speak Spanish.
 
pe1chl
Forum Guru
Forum Guru
Posts: 5927
Joined: Mon Jun 08, 2015 12:09 pm

Re: Problem sending multi-line command file via SSH

Fri Dec 09, 2016 8:08 pm

No. It works OK now.
 
sergeygtekb
just joined
Posts: 1
Joined: Tue Mar 20, 2018 12:12 pm

Re: Problem sending multi-line command file via SSH

Tue Mar 20, 2018 12:18 pm

Currently this is how ssh input is processed. Each line is treated as completely separate scripts that is why you get error when trying to send
/ip firewall mangle
add chain=whatever blah blah
Probably in the future it will be changed.
Have some chance to support multiline script via ssh?
ssh admin@my.mikrotik.org < ros_multiline.script

scp && ssh run - unwanted and thread unsave

Who is online

Users browsing this forum: MSN [Bot] and 72 guests