1

i want to make an ssh-connect to an remote host, there i want to run multiple commands.

ssh -l blabla 123.123.123.123 ls -l

when i run this, i will get the result of ls -l on 123.123...

Is it possible, to make sth like this:

ssh -l blabla 123.123.123.123 ls -l & ifconfig

... it tried this:

ssh -l blabla 123.123.123.123 ls -l; ifconfig

But there the local bash runs the second command. I want the second command to run on the remote host.

Thanks!

JohnPaul
  • 700
  • 5
  • 14
Mace
  • 13
  • 2
  • 7
  • Try to quote the `&` and `;` characters like this: `ssh user@host ls -l \; ifconfig` – Sven Jun 28 '16 at 12:06
  • ``ssh user@host 'command1; command2; command3'`` – terminal ninja Jun 28 '16 at 12:09
  • Both doesn't work. With \; the ; is converted to an normal character. And with "...;..." it's the same result: both commands are one command. The remote server tries to execute: >>ls -l \ ifconfig<< or >>ls -l; ifconfig< – Mace Jun 28 '16 at 12:14
  • 1
    Possible duplicate of [What is the cleanest way to ssh and run multiple commands in Bash?](https://stackoverflow.com/q/4412238/608639) – jww Aug 23 '19 at 20:41

2 Answers2

0

Just put all commands inside a quotes

ssh afont@123.123.123.123 "ls -l; ifconfig;"
AlbertFont
  • 26
  • 4
  • _Thank you, but the same problem as in the commends over your answer:_ Both doesn't work. With \; the ; is converted to an normal character. And with "...;..." it's the same result: both commands are one command. The remote server tries to execute: >>ls -l \ ifconfig<< or >>ls -l; ifconfig< – Mace Jun 28 '16 at 12:16
  • 2
    If this isn't working, perhaps you have an alias for `ssh` that is mangling the arguments. Try `type ssh`. – William Pursell Jun 28 '16 at 12:19
  • ah i found the Problem, it works Thank you! – Mace Jun 28 '16 at 12:25
0

You should try using "-t" before the commands:

ssh UserName@HostNameOrIP -t 'comand1 && command2'
eli-k
  • 8,496
  • 10
  • 38
  • 42
akjprajapati
  • 118
  • 2
  • 9