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!

4
  • Try to quote the & and ; characters like this: ssh user@host ls -l \; ifconfig Commented Jun 28, 2016 at 12:06
  • ssh user@host 'command1; command2; command3' Commented Jun 28, 2016 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<< Commented Jun 28, 2016 at 12:14
  • 1
    Possible duplicate of What is the cleanest way to ssh and run multiple commands in Bash? Commented Aug 23, 2019 at 20:41

2 Answers 2

1

Just put all commands inside a quotes

ssh [email protected] "ls -l; ifconfig;"
Sign up to request clarification or add additional context in comments.

3 Comments

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<<
If this isn't working, perhaps you have an alias for ssh that is mangling the arguments. Try type ssh.
ah i found the Problem, it works Thank you!
1

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

ssh UserName@HostNameOrIP -t 'comand1 && command2'

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.